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

时间:2020-01-31 00:09:31   收藏:0   阅读:111

 

  有时候我们需要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

原文:https://www.cnblogs.com/wbl001/p/12244331.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!