在jsp页面写的数据传到后台就变成null 30
控制层语句:@RequestMapping("/add")publicStringadd(Useruser){System.out.println("NAME------...
控制层语句:
@RequestMapping("/add")
public String add(User user){
System.out.println("NAME---------------"+user.getName());
userService.add(user); //调用service层的add方法,继而调用dao层的add方法添加用户
System.out.println("调用add方法");
return "redirect:/user/allUser"; //重定向到allUser方法
}
控制台显示:
NAME---------------null
Hibernate: insert into users (account, code, createdBy_id, created_at, department_id, enable, group_id, hashed_password, jobNumber, job_id, name, post_id, status_id, updateBy_id, updated_at, version) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
2015-1-6 21:06:53 org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 1048, SQLState: 23000
2015-1-6 21:06:53 org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: Column 'account' cannot be null
2015-1-6 21:06:53 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet springmvc threw exception
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'account' cannot be null
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.Util.getInstance(Util.java:381)
jsp页面一部分代码:
<form name="newUser" action="">
<div style="width:600px;" class="new_formateed">
<%-- <% form_for :user, :url => users_path, :html => {:id => "new_edit_frm", :name => "frm"} do |f| %>
--%>
<table border="0" cellpadding="0" cellspacing="0" class="table_border column2" width="100%">
<tr>
<td class="td_key">用户名:</td>
<td><input type="text" name="user.account"></input></td>
</tr>
<tr> 展开
@RequestMapping("/add")
public String add(User user){
System.out.println("NAME---------------"+user.getName());
userService.add(user); //调用service层的add方法,继而调用dao层的add方法添加用户
System.out.println("调用add方法");
return "redirect:/user/allUser"; //重定向到allUser方法
}
控制台显示:
NAME---------------null
Hibernate: insert into users (account, code, createdBy_id, created_at, department_id, enable, group_id, hashed_password, jobNumber, job_id, name, post_id, status_id, updateBy_id, updated_at, version) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
2015-1-6 21:06:53 org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 1048, SQLState: 23000
2015-1-6 21:06:53 org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: Column 'account' cannot be null
2015-1-6 21:06:53 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet springmvc threw exception
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'account' cannot be null
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.Util.getInstance(Util.java:381)
jsp页面一部分代码:
<form name="newUser" action="">
<div style="width:600px;" class="new_formateed">
<%-- <% form_for :user, :url => users_path, :html => {:id => "new_edit_frm", :name => "frm"} do |f| %>
--%>
<table border="0" cellpadding="0" cellspacing="0" class="table_border column2" width="100%">
<tr>
<td class="td_key">用户名:</td>
<td><input type="text" name="user.account"></input></td>
</tr>
<tr> 展开
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励10(财富值+成长值)+提问者悬赏30(财富值+成长值)
展开全部
如果你用的是spring mvc 那么在jsp页面就不能像struts2那样使用user.account,而是直接account,除非你自己做了扩展模拟struts2那样的参数绑定
更多追问追答
追问
如果改成那样的话,连null都传不进去了
HTTP Status 400 -
type Status report
message
description The request sent by the client was syntactically incorrect ().
Apache Tomcat/6.0.32
追答
那就是你代码没有完全说清楚吧,项目中spring mvc就是这么用的,而且我发现你的表单里面action都没写,如何提交?
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询