/** Delete user */ @ResponseBody @RequestMapping(value = "delete/{id}") public Map<String, Object> delete(Model model, @PathVariable int id) { userService.delete(id); Map<String, Object> map = new HashMap<String, Object>(); map.put("msg", "success"); return map; }
/** Create user */ @RequestMapping(value = "create") public String create( Model model, @RequestParam(value = "name") String name, @RequestParam(value = "age") int age) { User user = new User(); user.setName(name); user.setAge(age); user = userService.save(user); model.addAttribute("user", user); return "user"; }
/** update user */ @ResponseBody @RequestMapping(value = "update/{id}") public User update( Model model, @PathVariable int id, @RequestParam(value = "name", required = false) String name, @RequestParam(value = "age", required = false) int age) { User user = new User(); user.setId(id); if (null != name) { user.setName(name); } if (0 < age) { user.setAge(age); } userService.update(user); return user; }
/** list user */ @ResponseBody @RequestMapping(value = "list") public List<User> list(Model model) { List<User> users = userService.list(""); return users; }
/** get user */ @ResponseBody @RequestMapping(value = "get/{id}") public User get(Model model, @PathVariable int id) { User user = userService.get(id); return user; }