自增主键的返回

sql server的自增主键返回 只需要在insert语句后面添加SELECT  @@IDENTITY AS id

mysql的自增与非自增主键返回
mybatis自增主键返回
  
  

<mapper namespace="test">  
    <insert id="insertUser" parameterType="dancheng.mybatis.po.User">  
          
        <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Integer">  
            SELECT LAST_INSERT_ID()  
        selectKey>  
        insert into user(username,birthday,sex,address) value(#{username},#{birthday},#{sex},#{address})  
    insert>  
mapper>  

mybatis非自增主键返回

<mapper namespace="test">  
    <insert id="insertUser" parameterType="dancheng.mybatis.po.User">  
          
        <selectKey keyProperty="id" order="BEFORE" resultType="java.lang.String">  
            SELECT uuid()  
        selectKey>  
        insert into user(id,username,birthday,sex,address) value(#{id}.#{username},#{birthday},#{sex},#{address})  
    insert>  
mapper> 

你可能感兴趣的:(自增主键的返回)