Mybatis insert时自增主键为BigInt类型的,自增后需要使用主键,resultType如果写成int类型,插入不成功并报错exception argument mismatch
<!-- 插入一个商品 -->
<insert id="insertProduct" parameterType="domain.model.ProductBean" >
<selectKey resultType="java.lang.Long" order="AFTER" keyProperty="productId">
SELECT LAST_INSERT_ID()
</selectKey>
INSERT INTO t_product(productName,productDesrcible,merchantId)values(#{productName},#{productDesrcible},#{merchantId});
</insert>
探讨在MyBatis中插入数据时,对于BigInt类型的自增主键,如何正确设置resultType以避免插入失败及异常。通过示例展示如何使用<selectKey>元素获取LAST_INSERT_ID()。
2157

被折叠的 条评论
为什么被折叠?



