Column ‘列名’ cannot be null 问题解决

这个其实就是小错误,都怪自己的马虎。
它这里提示字段不能为空**,是因为数据库里加了非null约束。**
自己明明添加了数据,却没有进到数据库中。
我就检查了一下代码。


我这个是添加数据的方法,相信你们都能看出来吧,是的,没有返回值!!!
虽然很简单,但是这个错误我觉得很常犯。

写代码一定要找头脑清醒的时候写,不然只会给自己添麻烦!

org.springframework.dao.DataIntegrityViolationException:

Error updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException:
Column ‘name’ cannot be null
The error may involve defaultParameterMap
The error occurred while setting parameters
SQL: INSERT INTO users (name,sex,email) VALUES (?,?,?);
Cause:
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException:
Column ‘name’ cannot be null ; SQL []; Column ‘name’ cannot be null;
nested exception is
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException:
Column ‘name’ cannot be null
org.springframework.jdbc.support.SQLExceptionSubclassTranslator.doTranslate(SQLExceptionSubclassTranslator.java:85)
org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73)
org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:75)
org.mybatis.spring.SqlSessionTemplateSqlSessionInterceptor.invoke(SqlSessionTemplate.java:447)com.sun.proxy.SqlSessionInterceptor.invoke(SqlSessionTemplate.java:447) com.sun.proxy.SqlSessionInterceptor.invoke(SqlSessionTemplate.java:447)com.sun.proxy.Proxy9.insert(Unknown Source)
org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:279)
org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:57)
org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:53)
com.sun.proxy.$Proxy20.registerUser(Unknown Source)
com.myword.user.service.UserServiceImpl.registerUser(UserServiceImpl.java:28)
com.myword.user.controller.RedisController.registerUser(RedisController.java:32)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:497)
org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:832)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:743)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:961)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:895)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:967)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:858)
javax.servlet.http.HttpServlet.service(HttpServlet.java:635)

你可能感兴趣的:(bug解决,开发中遇到的bug)