执行下列一条语句:
flag = session.insert(ADDICON,icoBean);
<insert id="addIcon" parameterType="iconBean" flushCache="true" statementType="PREPARED">
<selectKey keyProperty="icoId" resultType="int" order="BEFORE">
select iconseq.nextval as icoId from dual
</selectKey>
insert into CTT_ICON
values
(
#{icoId},#{icoTypeId},#{icoDesc,jdbcType=VARCHAR},#{icoKey,jdbcType=VARCHAR},
#{icoFormat,jdbcType=VARCHAR},#{icoCity,jdbcType=VARCHAR},
#{icoCP,jdbcType=VARCHAR},#{icoWebUrl,jdbcType=VARCHAR},#{icoWapUrl,jdbcType=VARCHAR},
#{icoRequest,jdbcType=VARCHAR},#{icoNumber},#{icoStyle,jdbcType=DATE},#{icoUrl,jdbcType=VARCHAR},#{icoIndex,jdbcType=DATE},#{icoUpTime,jdbcType=DATE},
#{icoUsedNumber},#{icoName,jdbcType=VARCHAR},#{icoTag,jdbcType=VARCHAR},
#{icoIsAvaiable,jdbcType=VARCHAR},#{icoIsShow,jdbcType=VARCHAR},#{icoIsRecom,jdbcType=VARCHAR},#{icoIsHot,jdbcType=VARCHAR}
)
</insert>
然后你就可以拿到iconBean的主键,System.out.println(iconBean.getIconId());
这样居然可以取得到,也就是说你在执行插入的时候,ibatis3生成主键后,自动返回该主键的值到javaBean中。