selectKey 标签实现主键返回
keyColumn:主键对应的表中的哪一列
keyProperty:主键对应的pojo中的哪一个属性
order:设置在执行insert语句前执行查询id的sql,在执行insert语句之后执行查询id的sql
resultType:设置返回的id的类型
<insert id="save" parameterType="cc.yih.penn.entity.common.User">
<selectKey keyColumn="id" keyProperty="id" order="AFTER"
resultType="int">
SELECT LAST_INSERT_ID()
</selectKey>
INSERT INTO `user`
(user_name,pass_word,role,create_time) VALUES
(#{userName},#{passWord},#{role},NOW())
</insert>
获取主键ID;
int key = user.getId();
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。