引言
我们往DB中插入一条数据,使用Mybatis plus的BaseMapper#insert()方法时,如果实体类的主键成员是从自增序列中自动取值,而我们又不做任何标识的话会出现以下错误。出现主键数据很大而无法插入的问题。
org.apache.ibatis.reflection.ReflectionException:
Could not set property 'id' of 'class com.pojo.sallerPojo.TbBrand' with value '1077177904745537538'
Cause: java.lang.IllegalArgumentException: argument type mismatch
解决办法
解决方法也很简单。在该字段中添加@TableId(type=IdType.AUTO)注解即可。这样就会自动从自增序列中取nextVal。
public class MCompany implements Serializable {
// 添加type值,设置为自动
@TableId(type=IdType.AUTO)
private Integer companyId;
以下省略...