在进行java练习的过程中,对一个单链表进行增删改查时发现了如下错误:
对编译器的控制台进行检查之后,发现了报错语句如下:
2024-01-26 19:43:52.551 ERROR 18544 --- [p-nio-80-exec-5] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.DataIntegrityViolationException:
### Error updating database. Cause: java.sql.SQLIntegrityConstraintViolationException: Column 'number' cannot be null
### The error may exist in file [E:\javawork\springboot-mybatis\target\classes\mapper\StudentMapper.xml]
### The error may involve com.itheima.boot.mapper.StudentMapper.save-Inline
### The error occurred while setting parameters
### SQL: INSERT INTO springboot.tb_student (number, user_name, birthday, address) values (?,?,?,?)
### Cause: java.sql.SQLIntegrityConstraintViolationException: Column 'number' cannot be null
; Column 'number' cannot be null; nested exception is java.sql.SQLIntegrityConstraintViolationException: Column 'number' cannot be null] with root cause
java.sql.SQLIntegrityConstraintViolationException: Column 'number' cannot be null
看到number不能为空本人第一反应是属性名称错误导致没有映射成功,但是检查一遍之后发现原因出在:
控制层将服务层发送的数据封装为json数据发送到前端时,因为忘记了打上注释@RequestBody导致数据未封装为json即发送给前端,导致出现错误,如下图所示修改代码之后重启服务器即可正常执行增删改查操作.