mybatis 插入数据后获取id
<insert id="insertOne">
INSERT INTO table1 (term_text, name) VALUES (#{termText}, #{name});
<selectKey keyColumn="id" keyProperty="id" order="AFTER" resultType="java.lang.Integer">
select last_insert_id()
</selectKey>
</insert>
mybatis + mysql 时,在mapper.xml中可以使用select last_insert_id()获取最新插入数据的id.
金仓数据库不支持select last_insert_id()
<select id="createUserInfo" parameterType="com.xxx.Test" resultType="java.lang.Integer" flushCache="true">
insert into user_info
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="name != null">name,</if>
<if test="email != null">email,</if>
<if test="sex != null">sex,</if>
<if test="createdBy != null">created_by,</if>
<if test="createdTime != null">created_time</if>
</trim>
values
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="name != null">#{name},</if>
<if test="email != null">#{email},</if>
<if test="sex != null">#{sex},</if>
<if test="createdBy != null">#{createdBy},</if>
<if test="createdTime != null">#{createdTime}</if>
</trim>
returning id
</select>
通过returning可以获取id