PathVariable请求路径
时间: 2023-10-15 10:30:12 浏览: 83
@PathVariable是用来获取请求路径中参数的值的注解。它适用于restful风格的URL请求路径。比如,如果我们有一个请求路径是http://localhost:8806/mybatisDemo/detail/1,其中的1就是参数id的值。通过在方法上使用@GetMapping("/detail/{id}")注解,并在方法的参数上使用@PathVariable注解,我们可以获取到这个参数的值。例如:
@GetMapping("/detail/{id}")
public ApiResponse getApplicationById(@PathVariable Long id){
// 根据id查询数据
PubTest pubTest = mybatisDemoService.getById(id);
return success(pubTest);
}
在这个例子中,@PathVariable注解将会获取到路径中的id参数的值,然后我们可以使用这个值进行相关的业务处理。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [@PathVariable和@RequestParam的区别1](https://download.csdn.net/download/weixin_35762250/86363561)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [Springboot@PathVariable注解使用--请求路径占位符](https://blog.csdn.net/weixin_39709134/article/details/122804410)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [SpringMVC中获取请求路径参数@PathVariable 和@RequestBody以及@RequestParam的区别](https://blog.csdn.net/qq_52740442/article/details/119246981)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
阅读全文