MyBatis insert 语句返回id

1年前 ⋅ 537 阅读

方法一: <insert id="save" parameterType="com.example.demo.entity.User"> INSERT INTO t_student(name, sex, age) VALUES(#{name}, #{sex}, #{age}) <selectKey resultType="Integer" keyColumn="id" keyProperty="id" order="AFTER"> SELECT LAST_INSERT_ID() AS id </selectKey> </insert>

方法二: <insert id="save" parameterType="com.example.demo.entity.User" keyProperty="id" keyColumn="id" useGeneratedKeys="true"> INSERT INTO t_student(name, sex, age) VALUES(#{name}, #{sex}, #{age}) </insert>


全部评论: 0

    我有话说: