HomeController:
@RequestMapping(value="/resultmodel",method={RequestMethod.GET,RequestMethod.POST})
public ModelAndView add(@ModelAttribute("homeDTO") homeDTO hdto,Model model) {
ModelAndView view = new ModelAndView("resultmodel","homeDTO", new homeDTO());
model.addAttribute("homeDTO", hdto.getUserName());
return view;
}
结果Jsp
<h1>Result model</h1>
<form:form action="resultmodel" method="post" modelAttribute="modelform"> <!-- -->
<form:input type="text" path="homeDTO"/>
<input type="submit">
</form:form>
</body>
</html>
modelattribute名称与of @ modelattribute相同,但仍收到错误
基于验证的基于Spring MVC的表单示例的正确步骤: