在邮递员中发送 PathVariable @PostMapping

Dum*_*nga 7 java spring spring-mvc

我想在 post 映射中发送路径变量,在 postman 软件中。我选择了 post 映射正文,然后怎么办?我检查了@RequestParam vs @PathVariable示例,get 方法的所有答案,但我需要 post 方法的答案。

@RestController
@RequestMapping("api/v1/customers") 
public class CustomerController {

@PostMapping("/{code}")
    public String postRequest(@PathVariable String code,@RequestBody CustomerDTO dto){
         System.out.println(dto);
         System.out.println(code);
         return "Something";
    }
}
Run Code Online (Sandbox Code Playgroud)

小智 9

在此处输入图片说明

选择 post -> 添加 url -> 选择 body -> 选择 raw -> 选择 JSON(application/json) -> 添加你的 json 数据 -> 点击发送

  • 图片中显示的是 POST 正文,但问题是询问 Path 变量。您的回答与实际提出的问题无关。 (4认同)

小智 9

在邮递员中放置路径变量的简单方法是您的情况是“/:code”

检查链接以了解如何在 Postman 中添加路径变量

  • 欢迎来到 stackoverflow。我们中的一些人无法查看图像或点击链接。您可以张贴图片来代替吗?也许可以稍微延长一下你的解释? (2认同)