项目出现错误:
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: Could not set property ‘id’ of ‘class com.yep.springboot2022nocv.entity.NocvData’ with value ‘1588886217493360642’ Cause: java.lang.IllegalArgumentException: argument type mismatch] with root cause
原因是:数据库配置了主键主增,但是在项目中没有配置MybatisPlus的自增策略
解决办法
- 在实体类中的主键字段添加:
@TableId
注解
- SpringBoot中的配置文件
application.yml
也需要配置MybatisPlus的自增策略
id-type: auto
- 如果不在配置文件中设置这个属性的话,就需要在每个数据库的主键中设置自增策略