报错篇--MybatisPlus

项目出现错误:
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
    在这里插入图片描述
  • 如果不在配置文件中设置这个属性的话,就需要在每个数据库的主键中设置自增策略
    在这里插入图片描述

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