5.Map类型绑定
最灵活的一种方式,可无限绑定未定义的参数,注意必须绑定在对象下(ActionForm).
controller代码
- @RequestMapping
- public void test5(UserForm userForm)
- {
- System.out.println("Map类型绑定=========");
- System.out.println("名字:" + userForm.getUser().get("name"));
- System.out.println("年龄:" + userForm.getUser().get("age"));
- System.out.println("收入:" + userForm.getUser().get("income"));
- System.out.println("已结婚:" + userForm.getUser().get("isMarried"));
- System.out.println("========================");
- }
UserForm.java代码
- public class UserForm {
- private Map<String, String> userMap = new LinkedHashMap<String, String>();
- private User user = new User();
- public Map<String, String> getUserMap() {
- return userMap;
- }
- public void setUserMap(Map<String, String> userMap) {
- this.userMap = userMap;
- }
- public User getUser() {
- return user;
- }
- public void setUser(User user) {
- this.user = user;
- }
- }
转自:http://www.cnblogs.com/xd502djj/archive/2013/08/08/3245485.html