springMVC准确定位多个参数对象的属性
servlet类:
@Controller public class MyController01 { @InitBinder("customer") public void initBinder1(WebDataBinder binder){ binder.setFieldDefaultPrefix("customer."); } @InitBinder("user") public void initBinder2(WebDataBinder binder){ binder.setFieldDefaultPrefix("user."); } @RequestMapping(value = "/test.do", method = RequestMethod.POST) public ModelAndView firstTest(Customer customer, User user) { System.out.println(user == null ? null : " " + user.getPassword()); System.out.println("成功到达服务器! username: " + customer.getUsername() + " password:" + customer.getPassword()); return null; } }
jsp页面:
<form action="test.do" method="post" name="login">
<span>username:</span>
<input type="text" name="customer.username">
<br />
<span>password:</span>
<input type="password" name="user.password">
<input type="submit" value="commit">
</form>

浙公网安备 33010602011771号