Could not set property ‘xxx‘ of ‘class ‘xxx‘ with value ‘xxx‘

项目场景:

mysql设置的主键自增,在配置xml文件的时候未设置主键的值会报错


问题描述:

报错信息

错误信息

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: Could not set property 'id' of 'class com.huake.device.entity.HdbidEntity' with value '1324329405261471746' Cause: java.lang.IllegalArgumentException: argument type mismatch

原因分析:

在mybatis-plus中,如果主键是Integer类型,并且没有设置字段为主键自增,mybatis在执行插入语句是就会自动为主键设置一个值


解决方案:

1

在实体类中添加
@TableId(value = "id",type = IdType.AUTO)

字段著名该字段为主键自增的字段即可解决

2

将主键属性由Integer改成int类型

版权声明:本文为qq_46660780原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。