mybatis中的常用标签使用

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

猜你喜欢

转载自blog.csdn.net/weixin_42546892/article/details/84786459