使用selectKey
SelectKey在Mybatis中是为了解决Insert数据时不支持主键自动生成的问题,他可以很随意的设置生成主键的方式。
<insert id="insertSelective" parameterType="com.xxx.dao.webdb.model.ApayTxnLog">
insert into T_APAY_TXN_LOG
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="rowId != null">
ROW_ID,
</if>
<if test="fyDate != null">
FY_DATE,
</if>
<if test="fySsn != null">
FY_SSN,
</if>
<if test="merId != null">
MER_ID,
</if>
<if test="orderId != null">
ORDER_ID,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="rowId != null">
#{rowId,jdbcType=INTEGER},
</if>
<if test="fyDate != null">
#{fyDate,jdbcType=CHAR},
</if>
<if test="fySsn != null">
#{fySsn,jdbcType=CHAR},
</if>
<if test="merId != null">
#{merId,jdbcType=CHAR},
</if>
<if test="orderId != null">
#{orderId,jdbcType=VARCHAR},
</if>
</trim>
<selectKey resultType="java.lang.Integer" order="AFTER" keyProperty="rowId">
SELECT IDENTITY_VAL_LOCAL() FROM SYSIBM.SYSDUMMY1
</selectKey>
</insert>
参考
https://blog.csdn.net/weixin_43611145/article/details/86594218