使用useGeneratedKeys="true" keyProperty="id"时报错

报错内容如下:

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 into t_shopcart (user_id)
    	values(#{userId})
    
mapper.java中内容:
public int  insertShopCart(Integer userId);

需要返回自增主键,但是传入的参数为Integer 类型,返回的内容无法匹配;此时要么返回自增主键;要么把传入的参数改为javabean类,类中包含keyProperty="id"

转载于:https://my.oschina.net/u/3422045/blog/1113932

你可能感兴趣的:(使用useGeneratedKeys="true" keyProperty="id"时报错)