需求:使用MyBatis往MySQL数据库中插入一条记录后,需要返回该条记录的自增主键值。

 

方法:在mapper中指定keyProperty属性,示例如下:

 

<insert id="insertAndGetId" useGeneratedKeys="true" keyProperty="userId" 
 parameterType="com.chenzhou.mybatis.User">  
    insert into user(userName,password,comment)  
    values(#{userName},#{password},#{comment})  
</insert>  

 

 

 

 

 

 

 

 

 

 

 

 

参考文章: http://chenzhou123520.iteye.com/blog/1849881

相关文章:

  • 2021-08-26
  • 2018-01-18
  • 2021-07-28
  • 2021-07-25
猜你喜欢
  • 2022-12-23
  • 2022-02-14
  • 2021-10-07
  • 2021-10-30
  • 2021-07-19
  • 2022-12-23
  • 2021-07-19
相关资源
相似解决方案