在Spring MVC中,BeanResult'modelform'的BindingResult和普通目标对象都不能用作请求属性。请指教

问题描述 投票:1回答:1

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 spring-mvc spring-data
1个回答
0
投票

基于验证的基于Spring MVC的表单示例的正确步骤:

© www.soinside.com 2019 - 2024. All rights reserved.