【记录】mybatis获取刚刚插入到数据库的数据的id

  有时候我们需要mybatis获取insert 后的id,现有两种解决方案

方案一:

<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Integer">
      SELECT LAST_INSERT_ID()
    </selectKey>

  

方案二:

 <insert id="insert" parameterType="com.xxx" useGeneratedKeys="true" keyProperty="id">

  

再强调一下,AFTER     BEFORE必须大写

参考地址:https://blog.csdn.net/hehuihh/article/details/82800739

猜你喜欢

转载自www.cnblogs.com/wbl001/p/12244331.html
今日推荐