返回主键

  1. <?xml version="1.0" encoding="UTF-8" ?>  
  2. <!DOCTYPE mapper  
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"  
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">  
  5.   
  6. <mapper namespace="test">  
  7.     <insert id="insertUser" parameterType="dancheng.mybatis.po.User">  
  8.         <!--  
  9.             keyProperty:将查询出的主键设置到parameterType中的哪个属性上  
  10.             order:相对于sql语句的执行顺序  
  11.             resultType:指定返回值类型  
  12.             LAST_INSERT_ID():获取ID函数  
  13.         -->  
  14.         <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Integer">  
  15.             SELECT LAST_INSERT_ID()  
  16.         </selectKey>  
  17.         insert into user(username,birthday,sex,address) value(#{username},#{birthday},#{sex},#{address})  
  18.     </insert>  
  19. </mapper>  

 

  1. <mapper namespace="test">  
  2.     <insert id="insertUser" parameterType="dancheng.mybatis.po.User">  
  3.         <!--  
  4.             keyProperty:将查询出的主键设置到parameterType中的哪个属性上  
  5.             order:相对于sql语句的执行顺序  
  6.             resultType:指定返回值类型  
  7.             LAST_INSERT_ID():获取ID函数  
  8.         -->  
  9.         <selectKey keyProperty="id" order="BEFORE" resultType="java.lang.String">  
  10.             SELECT uuid()  
  11.         </selectKey>  
  12.         insert into user(id,username,birthday,sex,address) value(#{id}.#{username},#{birthday},#{sex},#{address})  
  13.     </insert>  
  14. </mapper>  

转载于:https://www.cnblogs.com/gtbky/p/8873100.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值