[Record] mybatis obtain data just inserted into the database id

 

  Sometimes we need mybatis get id after insert, available in two solutions

 

Option One:

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

  

Option II:

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

  

Again, AFTER BEFORE must be uppercase

 

Reference Address: https://blog.csdn.net/hehuihh/article/details/82800739

Guess you like

Origin www.cnblogs.com/wbl001/p/12244331.html