日期:2014-05-19  浏览次数:20668 次

spring mvc 的modelAttribute标签
本帖最后由 sweat89 于 2012-11-24 12:58:19 编辑

<form:form action="/student/addStudent" modelAttribute="student" method="post">
<table>
<tr>
<td><form:label path="name">Name</form:label></td>
<td><form:input path="name" /></td>
</tr>
<tr>
<td><form:label path="age">Age</form:label></td>
<td><form:input path="age" /></td>
</tr>
<tr>
<td><form:label path="id">id</form:label></td>
<td><form:input path="id" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Submit" />
</td>
</tr>
</table> 
</form:form> 





@Controller
@RequestMapping("/student")
public class StudentController {


@RequestMapping(value = "/addStudent",method = RequestMethod.POST)
public String addStudent(@ModelAttribute("student") Student student,BindingResult result) {
// model.addAttribute("student", student);
System.out.println("addStudent");
return "test";
}
}



一进入改JSP页面就报错:
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'student' available as request attribute

到底springMVC这个数据绑定 是个怎么绑定法,modelAttribute怎么用的,为什么我只是单单进入JSP页面,怎么会报错,springMVC form标签跟controller有什么直接联系么。
------解决方案--------------------
没人了解么。。。。