zoukankan      html  css  js  c++  java
  • 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中使用了

  • 相关阅读:
    苹果将首次采用HTML5直播发布会 狼人:
    Python 3.2 alpha 2发布 狼人:
    下一代Linux文件系统Btrfs走向成熟 狼人:
    Hello! 404 狼人:
    退格回车控制台输入密码
    poj 3233 Matrix Power Series
    地址参考clang: error: linker command failed with exit code 1 (use v to see invocation)
    文本截断JQuery为textarea添加maxlength,并且兼容IE
    代码下载Html5初探视频元素video示例
    c# 限制textbox的输入范围和长度(长度不用maxlength方法)
  • 原文地址:https://www.cnblogs.com/xh_Blog/p/9394578.html
Copyright © 2011-2022 走看看