springMVC封裝頁面Map型別資料
阿新 • • 發佈:2019-02-11
5.Map型別繫結
最靈活的一種方式,可無限繫結未定義的引數,注意必須繫結在物件下(ActionForm).
controller程式碼
[java] view plaincopyprint?- @RequestMapping
- publicvoid test5(UserForm userForm)
- {
- System.out.println("Map型別繫結=========");
- System.out.println("名字:" + userForm.getUser().get("name"));
- System.out.println("年齡:"
- System.out.println("收入:" + userForm.getUser().get("income"));
- System.out.println("已結婚:" + userForm.getUser().get("isMarried"));
- System.out.println("========================");
- }
UserForm.java程式碼
[java] view plaincopyprint?- publicclass
- private Map<String, String> userMap = new LinkedHashMap<String, String>();
- private User user = new User();
- public Map<String, String> getUserMap() {
- return userMap;
- }
- publicvoid setUserMap(Map<String, String> userMap) {
- this.userMap = userMap;
- }
- public
- return user;
- }
- publicvoid setUser(User user) {
- this.user = user;
- }
- }