MyBatis-Spring-Boot icon indicating copy to clipboard operation
MyBatis-Spring-Boot copied to clipboard

请教:怎么把 生成的 uuid 通过引用传递回去

Open tj123 opened this issue 8 years ago • 6 comments

研究您的代码的时候发现生成的 uuid 无法回传 想自己改一改结果实现不了

    <bind name="idDaDa_bind" value='@java.util.UUID@randomUUID().toString().replace("-", "")'/>
  
    <selectKey resultType="java.lang.String" order="AFTER" keyProperty="idDaDa">
      select #{idDaDa_bind,javaType=java.lang.String}
    </selectKey>
    
    INSERT INTO hehe5
    <trim prefix="(" suffix=")" suffixOverrides=",">id_da_da,hehe1,hehe2,hehe3,hehe4,hehe5,hehe6,</trim>
    <trim prefix="VALUES(" suffix=")" suffixOverrides=",">
      <if test="idDaDa != null">#{idDaDa,javaType=java.lang.String},</if>
      <if test="idDaDa == null">#{idDaDa_bind,javaType=java.lang.String},</if>
      <if test="hehe1 != null">#{hehe1,javaType=java.lang.String},</if>
      <if test="hehe1 == null">#{hehe1,javaType=java.lang.String},</if>
      <if test="hehe2 != null">#{hehe2,javaType=java.lang.String},</if>
      <if test="hehe2 == null">#{hehe2,javaType=java.lang.String},</if>
      <if test="hehe3 != null">#{hehe3,javaType=java.lang.String},</if>
      <if test="hehe3 == null">#{hehe3,javaType=java.lang.String},</if>
      <if test="hehe4 != null">#{hehe4,javaType=java.lang.String},</if>
      <if test="hehe4 == null">#{hehe4,javaType=java.lang.String},</if>
      <if test="hehe5 != null">#{hehe5,javaType=java.lang.String},</if>
      <if test="hehe5 == null">#{hehe5,javaType=java.lang.String},</if>
      <if test="hehe6 != null">#{hehe6,javaType=java.lang.String},</if>
      <if test="hehe6 == null">#{hehe6,javaType=java.lang.String},</if>
    </trim>

tj123 avatar Jun 08 '17 03:06 tj123

看这里: http://blog.csdn.net/isea533/article/details/53011890 或 https://mapperhelper.github.io/docs/3-2.mapper-uuid/

abel533 avatar Jun 08 '17 13:06 abel533

请问这种情况,在springboot集成通用mapper的时候,如何返回生成的uuid??

whling avatar Jun 22 '17 07:06 whling

@abel533

whling avatar Jun 22 '17 08:06 whling

@whling 看上面两个链接。

abel533 avatar Jun 22 '17 11:06 abel533

spring boot 的application.properties mapper.before=true mapper.not-empty=false mapper.ORDER=BEFORE [email protected]@uuid()

java对象的主键 @Id @Column(name = "Id") @GeneratedValue(generator ="UUID") private String id; 数据库可以插入uuid,java对象的主键还是为空,上面的两个链接也看了,没找到原因。

sun-soft avatar Jul 11 '17 08:07 sun-soft

@sun-soft 看上面两个链接,用可以回写的方式。

abel533 avatar Jul 12 '17 00:07 abel533