Currently learning Spring MVC with Spring 3, I'm trying to find the correct way to receive a form and handle it. That is what I've got at the moment :
@RequestMapping(method = RequestMethod.POST)
public String saveUserInfoIntoSession(Personne personne,
HttpSession session, ModelMap model) {
//
session.setAttribute("personne", personne);
return "ageAndAddress";
}
- Is this the correct 开发者_运维问答way to handle a SimpleForm ? As the SimpleFormController has been deprecated ...
- What if, Personne was not a class but an Interface, and I would like to, say, have an xml configuration find to decide which implementation I want to use ?
Thanks
You may simplify it to something like this...
@Controller
@SessionAttributes("personne")
public class MyController {
....
@RequestMapping(method = RequestMethod.POST)
public String saveUserInfoIntoSession(@ModelAttribute Personne personne, ModelMap model) {
return "ageAndAddress";
}
However, I would suggest you avoid passing form state via HTTP sessions. Request parameters + model is usually sufficient for most cases. If you have a complex wizard-like form, try better Spring WebFlow.
精彩评论