【发布时间】:2015-05-20 05:39:00
【问题描述】:
我的代码卡住了,我正在尝试传递对象“学生”的信息。我的场景是这样的:
注册表(填写详细信息,然后按提交按钮转到下一页)
从这个视图中,模型将被打印出来,然后再次按下下一步按钮。
第三页将再次显示信息。
问:我怎样才能将同一个对象传递给其他视图?
我的代码是这样的。
注册视图:
<form action="/HamburgerProject/stuSubmitAdmissionForm.html" method="post">
<table>
<tr>
<td>Name:</td> <td><input type="text" name="studentName"></td></tr>
<tr>
<td>Age:</td> <td><input type="text" name="studentAge"></td></tr>
<tr>
</table>
<input type="submit" value="submit this">
</form>
第一次信息查看:
<form action="/HamburgerProject/stuSubmitAdmissionForm.html" method="post">
<table>
<tr>
<td>Student's Name :</td>
<td>${student.studentName}</td>
</tr>
<tr>
<td>Student's Age :</td>
<td>${student.studentAge}</td>
</tr>
</table>
<input type="submit" value="send"/>
</form>
第二信息查看:
<table>
<tr>
<td>Student's Name :</td>
<td>${student.studentName}</td>
</tr>
<tr>
<td>Student's Age :</td>
<td>${student.studentAge}</td>
</tr>
</table>
我的控制者:
@RequestMapping(value="/stuAdmissionForm.html", method = RequestMethod.GET)
public ModelAndView getStudentAdmissionForm() {
ModelAndView model = new ModelAndView("AdmissionForm");
return model;
}
@RequestMapping(value="/stuSubmitAdmissionForm.html", method = RequestMethod.POST)
public ModelAndView submitModelAttributeAnnotationAdmissionForm(@ModelAttribute("student") Student student) {
ModelAndView model = new ModelAndView("AdmissionSuccess");
return model;
}
@RequestMapping(value="/stuDisplayForm.html", method = RequestMethod.POST)
public ModelAndView getStudent(Student student) {
ModelAndView model = new ModelAndView("NewForm");
model.addObject(student);
return model;
}
在尝试将信息从第二个视图重新显示到第三个视图时,对象 Student 没有被传递。
【问题讨论】:
-
第二种方法是什么?这里缺少将
student对象传递给model对象吗? -
嗨 Manu,第二种方法是从注册表中获取 Student 对象,然后将其显示在第二个信息视图上。
标签: java spring model-view-controller