http中5种常用请求方式: get、post、put 、delete、patch

1、get 请求

    /**
     * get请求
     *
     * @return
     */
    @GetMapping("user/list") // 等价于@RequestMapping(value="user/list",method=RequestMethod.GET)
    @ResponseBody
    public List<User> list(){
        // TODO
        return null;
    }

2、post 请求

    /**
     * post请求
     *
     * @param user
     * @return
     */
    @PostMapping("user/add") // 等价于@RequestMapping(value="user/add",method=RequestMethod.POST)
    @ResponseBody
    public List<User> add(@RequestBody User user){
        // TODO
        return null;
    }

3、put 请求

    /**
     * put请求
     *
     * @param userId
     * @param user
     * @return
     */
    @PutMapping("/user/{userId}") // 等价于@RequestMapping(value="/user/{userId}",method=RequestMethod.PUT)
    @ResponseBody
    public List<User> update(@PathVariable(value = "userId") Long userId,
                             @RequestBody User user){
        // TODO
        return null;
    }

4、delete 请求

    /**
     * delete请求
     *
     * @param userId
     * @return
     */
    @DeleteMapping("/user/{userId}") // 等价于@RequestMapping(value="/user/{userId}",method=RequestMethod.DELETE)
    @ResponseBody
    public List<User> delete(@PathVariable(value = "userId") Long userId){
        // TODO
        return null;
    }

5、patch 请求

    /**
     * patch请求
     *
     * @param user
     * @return
     */
    @PatchMapping("/user/profile") // 一般实际项目中,我们都是 PUT 不够用了之后才用 PATCH 请求去更新数据。
    @ResponseBody
    public List<User> updateUser(@RequestBody User user){
        // TODO
        return null;
    }


版权声明:本文为weixin_43652507原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。