【发布时间】:2019-04-16 22:49:09
【问题描述】:
我想在post mapping中发送路径变量,在postman软件中。我选择post mapping body,然后怎么做?我检查了@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";
}
}
【问题讨论】:
-
PathVariable是 URL 的一部分 -
您可以像这样在邮递员中使用 uri "localhost:8080/api/v1/customers/{code}" 选择帖子下拉列表并发送请求。
-
不,我们不能在 post 映射中通过 url 发送值,换句话说,我们不能在 post 方法中编辑 url
标签: java spring spring-mvc