RequestMapping , GetMapping , PostMapping 区别与联系

①、RequestMapping 如果不指定请求方式, 那么既可以接受 Post请求, 也可以接受Get请求。

示例 : 通过 get 和 post 都能获取我们所需的结果 。

	@RequestMapping("/userLists")  
    public List<User> getUsers() {
        return userService.getAllUser();
    }

②、PostMapping 与 GetMapping 指定了 请求接口的具体方法 ,

  • PostMapping 等价于 RequestMapping 指定 为Post请求

  • GetMapping 等价于 RequestMapping 指定 为Get请求

注解源码

RequestMapping , GetMapping , PostMapping 区别与联系_第1张图片

你可能感兴趣的:(SpringBoot)