mybatis自定义插入主键
Order这个属性设为after,before这个执行顺序都是相对于下面的insert into这个sql的;
Order设为before:那么就先执行selectkey这个标签的sgl,再将这条sql生成的uuid set到User里面去,然后再执行insert into将这个已经带uuid为id的这个User insert到数据库中.
<!--自增主键之UUID-->
<insert id="insertUser" parameterType="com.test.mybatis.po.User">
  <!--只要不是自增主键,那么order都设置为before-->
  <selectkey keyProperty="id" resultrype="string" order="BEFORE">
  	SELECT UUID()
  </selectkey>
  INSERT INTO USER (ID,USERNAME,BIRTHDAY,SEX,ADDRESS)
  VALUES (#{id},#{username},#{birthday},#{sex},#{address})
</insert>
本文来自博客园,作者:bgtong,转载请注明原文链接:https://www.cnblogs.com/bgtong/p/16535507.html
 
                    
                     
                    
                 
                    
                 
         
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号