Ivorybeach
2017-12-02 03:31 浏览 2.6k
已采纳

column "" can not be null springmvc+mybatis

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.dao.DataIntegrityViolationException:

Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'userName' cannot be null

The error may exist in com/demo/dao/UserMapper.xml

The error may involve com.demo.dao.UserMapper.insertUser-Inline

The error occurred while setting parameters

SQL: insert into user (userName,password,id) values (?,?,?)

Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'userName' cannot be null

; SQL []; Column 'userName' cannot be null; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'userName' cannot be null
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:927)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:811)
javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:796)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107

一直提示字段不能为空,这是因为没有接收到页面的请求参数吗?所以#{}接收不到值?怎样解决,求好心人搭救,感谢!

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答 默认 最新

  • 已采纳
    D1208 D1208 2017-12-02 03:43

    检查一下传入sql的对象,看看里面userName的属性值是否为null!你数据库表设计的userName不能为null的

    点赞 评论 复制链接分享
  • FlyAngle1 我是一只小小小小小鸟 2017-12-02 04:47

    在Controller里打印一下username看页面传过来没,再检查Service有没有丢失

    点赞 评论 复制链接分享

相关推荐