Data binding without using spring taglib

走远了吗. 提交于 2019-12-04 12:15:34
nickdos

You could try including the BindingResult class in the method signature and then see if there are any binding errors:

@RequestMapping("login")
Public ModelAndView doLogin(FrAccUserMgmt frAccUserMgmt, BindingResult result) {
    if (result.hasErrors()) {
        logger.warn("BindingResult errors: " + result.toString());
    }
    //code
}

Remove the frAccUserMgmt part from the form field names. Spring will automatically find the command object to bind the request parameters based on the getters and setters defined in the command object.

This can also be done by adding the @ModelAttribute for the parameter bean that should be populated with the request parameters.

As per spring docs

http://docs.spring.io/spring/docs/3.1.x/spring-framework-reference/html/mvc.html#mvc-ann-modelattrib-method-args (16.3.3.8 Using @ModelAttribute on a method argument)

An @ModelAttribute on a method argument indicates the argument should be retrieved from the model. If not present in the model, the argument should be instantiated first and then added to the model. Once present in the model, the argument's fields should be populated from all request parameters that have matching names. This is known as data binding in Spring MVC, a very useful mechanism that saves you from having to parse each form field individually.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!