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

/ OracleMyBatisJava / 没有评论 / 326浏览

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>