zoukankan      html  css  js  c++  java
  • 使用注解 @RequestParam 和 @PathVariable 在 Postman 测试中一些注意事项

    @PathVariable

    路径占位符,用于定义路径变量。

        @DeleteMapping("/deleteUser/{id}")
        public RespBean deleteUser(@PathVariable Integer id){
            if (userService.deleteUser(id) == 1){
                return RespBean.ok("删除成功!");
            }
            return RespBean.error("删除失败!");
        }
    

    这个 delete 请求方法的 URL 是这样的:http://localhost:8080/deleteUser/22,这个 22 就是前端传的 id 值。

    在 postman 测试中,如下图,直接将 id 值写在 URL 中

    @RequestParam

    @RequestParam 是传递参数的,用于将请求参数映射到 URL 中。

        @DeleteMapping("/deleteUser")
        public RespBean deleteUser(@RequestParam Integer id){
            if (userService.deleteUser(id) == 1){
                return RespBean.ok("删除成功!");
            }
            return RespBean.error("删除失败!");
        }
    

    这个 delete 请求方法的 URL 是这样的:http://localhost:8080/deleteUser?id=23,这个 23 就是前端传的 id 值。

    在 postman 测试中,将 id 参数以 key-value 的形式,写在 params 中:

    两者的效果是一样的,同样删除了一个指定的 user。

    参考资源

    https://blog.csdn.net/a15028596338/article/details/84976223

  • 相关阅读:
    2004选拔赛 最小值
    [JSOI2008]最大数maxnumber
    HDOJ 2896 病毒侵袭
    POJ 2243 Knight Moves
    HDOJ Is It A Tree?
    MST 小希的迷宫
    PKU 3278 Catch That Cow
    POJ 2488 A Knight's Journey
    [SCOI2006]整数划分
    COJ 1259: 跳跳
  • 原文地址:https://www.cnblogs.com/youcoding/p/15119104.html
Copyright © 2011-2022 走看看