Skip to content

Modified the mapping method #135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* Created by bysocket on 24/07/2017.
*/
@Controller
@RequestMapping(value = "/users") // 通过这里配置使下面的映射都在 /users
@GetMapping("/users") // 通过这里配置使下面的映射都在 /users
public class UserController {

@Autowired
Expand All @@ -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");
Expand All @@ -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) {
Expand All @@ -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");
Expand All @@ -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) {
Expand All @@ -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/";
}
}
}