JZ0NK |
Description: The getGeneratedKeys() method is unable to return the auto-generated keys because the statement was executed with .NO_GENERATED_KEYS or the statement produced no auto-generated keys. Action: Use getGeneratedKeys() only on statements executed with .RETURN_GENERATED_KEYS or those that are expected to auto-generate keys. |
<insert id="insert" parameterType="com.talkweb.zqgzt.service.pojo.BAS_FILE">
<selectKey resultType="integer" order="AFTER" keyProperty="ID">
select @@IDENTITY as ID
</selectKey>
INSERT INTO BAS_FILE (
<if test="FJMC!=null">FJMC,</if>
<if test="PATH!=null">PATH,</if>
SCSJ
) VALUES(
<if test="FJMC!=null">#{FJMC},</if>
<if test="PATH!=null">#{PATH},</if>
getdate()
)
</insert>
这样返回的主键值永远是0,使用下面这种BT的搞法,居然可以返回正确的值:
<select id="selectInsert" parameterType="com.talkweb.zqgzt.service.pojo.BAS_FILE" resultType="int">
INSERT INTO BAS_FILE (
<if test="FJMC!=null">FJMC,</if>
<if test="PATH!=null">PATH,</if>
SCSJ
) VALUES(
<if test="FJMC!=null">#{FJMC},</if>
<if test="PATH!=null">#{PATH},</if>
getdate()
)
select @@IDENTITY as ID
</select>
在DAO层使用 selectOne()方法来取得主键值。