selec"> select LAST_I..._ selec">
当前位置:   article > 正文

关于java插入数据返回主键问题_

selec

我之前以为在xml中设置了useGeneratedKeys="true" keyProperty="id"就可以了
其实不然,这只是返回自增主键id。
如果用的是uuid字符串我就们就需要在下面加入一行代码

<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
      select LAST_INSERT_ID()
</selectKey>
  • 1
  • 2
  • 3

xml示例代码

<insert id="insertSelective" parameterType="com.demo.GoodsSpecPO" useGeneratedKeys="true" keyProperty="id">
    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
      select LAST_INSERT_ID()
    </selectKey>
    insert into table_name
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="specIndex != null">
        spec_index,
      </if>
      <if test="name != null">
        `name`,
      </if>
      <if test="type != null">
        `type`,
      </if>
      <if test="categoryId != null">
        category_id,
      </if>
      <if test="creator != null">
        creator,
      </if>
      <if test="creatorId != null">
        creator_id,
      </if>
      <if test="updator != null">
        updator,
      </if>

        create_time,

        update_time,

        deleted,

      <if test="version != null">
        version,
      </if>
    </trim>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/241447
推荐阅读
相关标签
  

闽ICP备14008679号