Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is

原因①:在表设计的时候,设置了这个数据不能重复,即表中已经存在了“就业部”这个消息了,所以报错。

控制台报错信息:

java.sql.SQLIntegrityConstraintViolationException: Duplicate entry '就业部' for key 'dept.name'
; Duplicate entry '就业部' for key 'dept.name'; nested exception is java.sql.SQLIntegrityConstraintViolationException: Duplicate entry '就业部' for key 'dept.name'] with root cause

原因②:id的信息为空,但是我们又想让数据库自动递增

原因是我使用的是mybatisplus提供的一些函数,然后id在数据库中设置为自增的,需要在application.properties中添加以下语句

mybatis-plus.global-config.db-config.id-type=auto

日志输出 ERROR 7492 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : 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.example.entity.Dept' with value '1712065931527610369' Cause: java.lang.IllegalArgumentException: argument type mismatch] with root cause

以上原因接口测试都会出现500

 

posted on 2023-10-11 19:31  201812  阅读(663)  评论(0)    收藏  举报