@ModelAttribute("user") public User getUser() { User user = new User(); user.setUserId("1001"); user.setUserName("<>"); return user; }
public void udateLoginInfo(User user) { String sqlStr = "update t_user set last_visit = ?,last_ip = ?,credits = ? " + " where user_id = ? "; jdbcTemplate.update( sqlStr, new Object[] {user.getLastVisit(), user.getLastIp(), user.getCreadits(), user.getUserId()}); }
@RequestMapping(value = "/handle63") public String handle63(ModelMap modelMap) { User user = (User) modelMap.get("user"); user.setUserName("tom"); modelMap.addAttribute("testAttr", "value1"); return "/user/showUser"; }
@RequestMapping(value = "/handle72") public String handle72(ModelMap modelMap, SessionStatus sessionStatus) { User user = (User) modelMap.get("user"); if (user != null) { user.setUserName("Jetty"); sessionStatus.setComplete(); } return "/user/showUser"; }
@RequestMapping(value = "/handle92") public String handle92(@ModelAttribute("user") User user, BindingResult bindingResult) { ValidationUtils.rejectIfEmptyOrWhitespace(bindingResult, "userName", "required"); if ("aaaa".equalsIgnoreCase(user.getUserName())) { bindingResult.rejectValue("userName", "reserved"); } if (bindingResult.hasErrors()) { return "/user/register4"; } else { return "/user/showUser"; } }
@RequestMapping(value = "/showUserListMix") public String showUserListMix(ModelMap mm) { Calendar calendar = new GregorianCalendar(); List<User> userList = new ArrayList<User>(); User user1 = new User(); user1.setUserName("tom"); user1.setRealName("汤姆1"); calendar.set(1980, 1, 1); user1.setBirthday(calendar.getTime()); User user2 = new User(); user2.setUserName("john"); user2.setRealName("约翰"); user2.setBirthday(calendar.getTime()); userList.add(user1); userList.add(user2); mm.addAttribute("userList", userList); return "userListMix"; }
@RequestMapping(value = "/handle71") public String handle71(@ModelAttribute("user") User user) { user.setUserName("John"); return "redirect:handle72.html"; }
@ModelAttribute("user2") public User getUser2() { User user = new User(); user.setUserId("1"); return user; }
@RequestMapping(value = "/handle62") public String handle62(@ModelAttribute("user") User user) { user.setUserName("tom"); return "/user/showUser"; }
@RequestMapping(value = "/handle61") public String handle61(@ModelAttribute("user") User user) { user.setUserId("1000"); return "/user/createSuccess"; }
@RequestMapping(value = "/handle51") public ResponseEntity<User> handle51(HttpEntity<User> requestEntity) { User user = requestEntity.getBody(); user.setUserId("1000"); return new ResponseEntity<User>(user, HttpStatus.OK); }