springmvc同名参数绑定支持

@Controller
public class TestBinderController {

    @InitBinder("account")
    public void initBinder1(WebDataBinder binder) {
            binder.setFieldDefaultPrefix("acc.");
    }
    @InitBinder("user")
    public void initBinder2(WebDataBinder binder) {
            binder.setFieldDefaultPrefix("user.");
    }

    @RequestMapping("/testInput")
    public String testBinderInput(){
       return "testInput";
    }

    @RequestMapping("/testOutput")
    public void testBinderOuput(@ModelAttribute Account account,@ModelAttribute User user,BindingResult result){
        System.out.println(user);
        System.out.println(account);
    }
}
<html>

<body>
<form action="/testOutput" method="post">
    <input name="acc.loginId">
    <input name="user.loginid">
    <input type="submit">
</form>
</body>
</html>


你可能感兴趣的:(springmvc同名参数绑定支持)