@RequestMapping(value = EDIT_URL, method = RequestMethod.GET) @ResponseBody public String editUser( @RequestParam(value = SELECTED_ID_PARAM, required = true) String id, @RequestParam(value = NAME_PARAM, required = true) String name, @RequestParam(value = SECOND_NAME_PARAM, required = true) String secondName, @RequestParam(value = AGE_PARAM, required = true) String age) { User user = userService.get(Long.parseLong(id)); user.setName(name); user.setSecondName(secondName); user.setAge(Integer.parseInt(age)); // user.setRegistrationDate(new Date()); userService.update(user); return "User successfully edited. " + REFRESH_PAGE_MESSAGE; }
@RequestMapping(value = DELETE_URL, method = RequestMethod.GET) @ResponseBody public String deleteUsers(@RequestParam(value = SELECTED_IDS_PARAM, required = true) String ids) { List<Long> parsedIds = parseIds(ids); userService.delete(parsedIds); return "Users were successfully deleted. " + REFRESH_PAGE_MESSAGE; }
@RequestMapping( value = WELCOME_PAGE_URL, method = {RequestMethod.GET, RequestMethod.HEAD}) public String getWelcomePage(HttpSession session) { session.setAttribute(USERS_SESSION, userService.getAll()); return MAIN_PAGE; }
@RequestMapping(value = GET_URL, method = RequestMethod.GET) @ResponseBody public String getUser(@RequestParam(value = SELECTED_ID_PARAM, required = true) String id) { User user = userService.get(Long.parseLong(id)); Map<String, String> userMap = new LinkedHashMap<String, String>(); userMap.put(NAME_PARAM, user.getName()); userMap.put(SECOND_NAME_PARAM, user.getSecondName()); userMap.put(AGE_PARAM, String.valueOf(user.getAge())); return JSONValue.toJSONString(userMap); }
@RequestMapping(value = SAVE_URL, method = RequestMethod.GET) @ResponseBody public String saveUser( @RequestParam(value = NAME_PARAM, required = true) String name, @RequestParam(value = SECOND_NAME_PARAM, required = true) String secondName, @RequestParam(value = AGE_PARAM, required = true) String age) { User user = new User(); user.setName(name); user.setSecondName(secondName); user.setAge(Integer.parseInt(age)); user.setRegistrationDate(new Date()); userService.add(user); return "User successfully created. " + REFRESH_PAGE_MESSAGE; }