From 7c1b9e081addbdf65630d6847771d0b94cd1e408 Mon Sep 17 00:00:00 2001 From: Ramesh Prasad <58248453+Rameshpd2748@users.noreply.github.com> Date: Mon, 11 Oct 2021 18:02:03 +0530 Subject: [PATCH] Modified the mapping method --- .../java/spring/boot/core/web/UserController.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/chapter-4-spring-boot-validating-form-input/src/main/java/spring/boot/core/web/UserController.java b/chapter-4-spring-boot-validating-form-input/src/main/java/spring/boot/core/web/UserController.java index 8a51c844..0344bcf1 100644 --- a/chapter-4-spring-boot-validating-form-input/src/main/java/spring/boot/core/web/UserController.java +++ b/chapter-4-spring-boot-validating-form-input/src/main/java/spring/boot/core/web/UserController.java @@ -19,7 +19,7 @@ * Created by bysocket on 24/07/2017. */ @Controller -@RequestMapping(value = "/users") // 通过这里配置使下面的映射都在 /users +@GetMapping("/users") // 通过这里配置使下面的映射都在 /users public class UserController { @Autowired @@ -42,7 +42,7 @@ public String getUserList(ModelMap map) { * @param map * @return */ - @RequestMapping(value = "/create", method = RequestMethod.GET) + @GetMapping("/create") public String createUserForm(ModelMap map) { map.addAttribute("user", new User()); map.addAttribute("action", "create"); @@ -54,7 +54,7 @@ public String createUserForm(ModelMap map) { * 处理 "/users" 的 POST 请求,用来获取用户列表 * 通过 @ModelAttribute 绑定参数,也通过 @RequestParam 从页面中传递参数 */ - @RequestMapping(value = "/create", method = RequestMethod.POST) + @GetMapping( "/create") public String postUser(ModelMap map, @ModelAttribute @Valid User user, BindingResult bindingResult) { @@ -75,7 +75,7 @@ public String postUser(ModelMap map, * 处理 "/users/{id}" 的 GET 请求,通过 URL 中的 id 值获取 User 信息 * URL 中的 id ,通过 @PathVariable 绑定参数 */ - @RequestMapping(value = "/update/{id}", method = RequestMethod.GET) + @GetMapping("/update/{id}") public String getUser(@PathVariable Long id, ModelMap map) { map.addAttribute("user", userService.findById(id)); map.addAttribute("action", "update"); @@ -86,7 +86,7 @@ public String getUser(@PathVariable Long id, ModelMap map) { * 处理 "/users/{id}" 的 PUT 请求,用来更新 User 信息 * */ - @RequestMapping(value = "/update", method = RequestMethod.POST) + @PostMapping("/update") public String putUser(ModelMap map, @ModelAttribute @Valid User user, BindingResult bindingResult) { @@ -103,10 +103,10 @@ public String putUser(ModelMap map, /** * 处理 "/users/{id}" 的 GET 请求,用来删除 User 信息 */ - @RequestMapping(value = "/delete/{id}", method = RequestMethod.DELETE) + @DeleteMapping("/delete/{id}") public String deleteUser(@PathVariable Long id) { userService.delete(id); return "redirect:/users/"; } -} \ No newline at end of file +}