这可以通过以下方式完成:
@Controller
public class PageController {
@RequestMapping("/page1")
public String showPage1(Model model) {
Obj obj = new Obj();
model.addAttribute("obj", obj);
return "test/page1";
}
@RequestMapping("/page2")
public String showPage2(@ModelAttribute Obj obj, Model model) {
model.addAttribute("obj", obj);
return "test/page2";
}
@RequestMapping("/page3")
public String showPage3(@ModelAttribute Obj obj, Model model) {
model.addAttribute("obj", obj);
return "test/page3";
}
}
第 1 页(仅相关部分):
<sf:form modelAttribute="obj" action="page2">
<sf:input path="field1"/><br/>
<sf:input path="field2"/><br/>
<sf:input path="field3"/><br/>
<input type="submit" value="To page 2">
</sf:form>
第2页:
<sf:form modelAttribute="obj" action="page3">
<sf:hidden path="field1"/>
<sf:hidden path="field2"/>
<sf:hidden path="field3"/>
<sf:input path="field4"/><br/>
<sf:input path="field5"/><br/>
<input type="submit" value="To page 3">
</sf:form>
第 3 页仅用于显示在前 2 页输入的所有对象字段。