报错内容如下:
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.executor.ExecutorException: Error getting generated key or setting result to parameter object. Cause: org.apache.ibatis.executor.ExecutorException: No setter found for the keyProperty 'id' in java.lang.Integer
mapper.xml中内容:
<insert id="insertShopCart" useGeneratedKeys="true" keyProperty="id">
insert into t_shopcart (user_id)
values(#{userId})
</insert>
mapper.java中内容:
public int insertShopCart(Integer userId);
需要返回自增主键,但是传入的参数为Integer 类型,返回的内容无法匹配;此时要么返回自增主键;要么把传入的参数改为javabean类,类中包含keyProperty="id"