mybatis插入值的时候返回对象的主键值

mapping文件:

<insert id="insert" parameterType="com.vimtech.bms.business.riskprojectapproval.domain.RiskProjectApproval" >
    insert into WF_RISK_PROJECT_APPROVAL (RISKTGID, PROJID, CREATEDATE, 
      UPDATEDATE, STATUS, CONCLUSION, 
      CREATOR, RISKTYPE, APPLYTYPE, 
      ISCOMPENSATORY)
    values (#{risktgid,jdbcType=NUMERIC}, #{projid,jdbcType=NUMERIC}, #{createdate,jdbcType=TIMESTAMP}, 
      #{updatedate,jdbcType=TIMESTAMP}, #{status,jdbcType=INTEGER}, #{conclusion,jdbcType=VARCHAR}, 
      #{creator,jdbcType=VARCHAR}, #{risktype,jdbcType=INTEGER}, #{applytype,jdbcType=INTEGER}, 
      #{iscompensatory,jdbcType=INTEGER})
      <selectKey resultType="long" keyProperty="risktgid">
        SELECT @@IDENTITY AS RISKTGID
      </selectKey>
  </insert>
  <insert id="insertSelective" parameterType="com.vimtech.bms.business.riskprojectapproval.domain.RiskProjectApproval" >
    insert into WF_RISK_PROJECT_APPROVAL
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="risktgid != null" >
        RISKTGID,
      </if>
      <if test="projid != null" >
        PROJID,
      </if>
      <if test="createdate != null" >
        CREATEDATE,
      </if>
      <if test="updatedate != null" >
        UPDATEDATE,
      </if>
      <if test="status != null" >
        STATUS,
      </if>
      <if test="conclusion != null" >
        CONCLUSION,
      </if>
      <if test="creator != null" >
        CREATOR,
      </if>
      <if test="risktype != null" >
        RISKTYPE,
      </if>
      <if test="applytype != null" >
        APPLYTYPE,
      </if>
      <if test="iscompensatory != null" >
        ISCOMPENSATORY,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="risktgid != null" >
        #{risktgid,jdbcType=NUMERIC},
      </if>
      <if test="projid != null" >
        #{projid,jdbcType=NUMERIC},
      </if>
      <if test="createdate != null" >
        #{createdate,jdbcType=TIMESTAMP},
      </if>
      <if test="updatedate != null" >
        #{updatedate,jdbcType=TIMESTAMP},
      </if>
      <if test="status != null" >
        #{status,jdbcType=INTEGER},
      </if>
      <if test="conclusion != null" >
        #{conclusion,jdbcType=VARCHAR},
      </if>
      <if test="creator != null" >
        #{creator,jdbcType=VARCHAR},
      </if>
      <if test="risktype != null" >
        #{risktype,jdbcType=INTEGER},
      </if>
      <if test="applytype != null" >
        #{applytype,jdbcType=INTEGER},
      </if>
      <if test="iscompensatory != null" >
        #{iscompensatory,jdbcType=INTEGER},
      </if>
    </trim>
    <selectKey resultType="long" keyProperty="risktgid">
          SELECT @@IDENTITY AS RISKTGID
    </selectKey>
  </insert>

如上中的selectKey中的写法即可,然后就可以在action中使用了

转载于:https://www.cnblogs.com/xh_Blog/p/9394578.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值