mybatis 插入数据 在没有commit时 获取主键id

Posted Superb1995

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mybatis 插入数据 在没有commit时 获取主键id相关的知识,希望对你有一定的参考价值。

  1.  
    <insert id="insert" parameterType="Mail" useGeneratedKeys="true" keyProperty="id_note">
  2.  
    insert into note(sender, from_address, subject, content, send_time)
  3.  
    values(#{sender}, #{fromAddress}, #{subject}, #{content}, #{sendTime})
  4.  
    <selectKey keyProperty="id_mail" resultType="int">
  5.  
    select LAST_INSERT_ID()
  6.  
    </selectKey>
  7.  
    </insert>
  8.  

 

  1. <!--这里可以获得刚插入表格的id,为后面attachment的插入提供了mailId字段-->
  2.  
    <select id="selectLastId" resultType="int">
  3.  
    select LAST_INSERT_ID()
  4.  
    </select>
  5.  

以上是关于mybatis 插入数据 在没有commit时 获取主键id的主要内容,如果未能解决你的问题,请参考以下文章