我正在MySQL 5.5.46
使用MyBatis 3.3
和Spring 4.2
。我有一个表格,其主键列的类型为VARCHAR(32)
。在我的映射文件中,我有这个声明。请注意,我使用MySql的uuid()
来自动生成ID。然后我如何获取此ID并将其填充到返回的对象中?我正在尝试LAST_INSERT_ID()
,但那不是在做......
<insert id="insertMyObject" parameterType="org.mainco.myproject.domain.MyObject" keyProperty="id" keyColumn="id">
insert into cb_myproject_sync_entity_link(id, links_self, links_schools, links_teachers, links_students, links_sections, links_grade_levels, links_contacts)
values(replace(uuid(), '-', ''),#{linksSelf}, #{linksSchools}, #{linksTeachers}, #{linksStudents}, #{linksSections}, #{linksGradeLevels}, #{linksContacts})
<selectKey keyProperty="id" resultType="String" order="AFTER">SELECT LAST_INSERT_ID();</selectKey>
</insert>
答案 0 :(得分:0)
尝试在mybatis配置中使用此设置:
<settings>
<setting name="useGeneratedKeys" value="true"/>
</settings>