【发布时间】:2016-01-22 00:28:18
【问题描述】:
我将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>
【问题讨论】:
标签: mysql insert mybatis auto-generate