selectKey标签:
<insert id="insertUser" parameterType="com.danny.mybatis.po.User">
<selectKey keyProperty="userId" order="AFTER" resultType="java.lang.Integer">
select LAST_INSERT_ID()
</selectKey>
insert into T_USER(userName,birthday,sex,address) values (#{userName},#{birthday},#{sex},#{address})
</insert>
keyProperty:将查询到的主键值设置到parameterType指定对象的哪个属性。
order:<selectKey>
标签内的sql语句相对于insert
语句的执行顺序,AFTER
表示select LAST_INSERT_ID()
这个语句将在insert
语句之后执行。()
添加一条数据得到添加完之后的id主键
加上三个标签
https://blog.csdn.net/u012470138/article/details/53171476
《foreach的三种用法 (List array Map)》
https://blog.csdn.net/ferdinand1993/article/details/80964168