当前位置:首页 > 数据库 > 正文

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

2024-03-31 数据库

 

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

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/SQL/12253.html