美文网首页
Mybatis+Oracle添加1条数据并返回数据的主键问题

Mybatis+Oracle添加1条数据并返回数据的主键问题

作者: zxk175 | 来源:发表于2017-03-16 11:40 被阅读87次

    Controller类

    @RequestMapping(value = "/upload/{lid}", method = RequestMethod.POST)
    public void toUploap(@PathVariable String lid, TAppPicList pic)  {
        // pic是添加的数据, apppicid为数据主键,此时对象中主键为null
        picService.insertPic(pic);
        // 获取对象主键
        System.out.println("返回的主键值是"+pic.getApppicid()); 
    }
    

    Mapperx.xml

    <insert id="insertPic" parameterType="com.zxk175.ssm.model.TAppPicList" >
        <selectKey keyProperty="apppicid" resultType="String" order="BEFORE">
          SELECT  'P00'||SQ_APPPICID.nextval as apppicid from dual
        </selectKey>
        insert into T_APP_PICLIST
        <trim prefix="(" suffix=")" suffixOverrides=",">
          <if test="apppicid != null">
            APPPICID,
          </if>
          <if test="appid != null">
            APPID,
          </if>
          <if test="orderno != null">
            ORDERNO,
          </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
          <if test="apppicid != null">
            #{apppicid,jdbcType=VARCHAR},
          </if>
          <if test="appid != null">
            #{appid,jdbcType=VARCHAR},
          </if>
          <if test="orderno != null">
            #{orderno,jdbcType=VARCHAR},
          </if>
        </trim>
      </insert>
    

    相关文章

      网友评论

          本文标题:Mybatis+Oracle添加1条数据并返回数据的主键问题

          本文链接:https://www.haomeiwen.com/subject/ldndnttx.html