@RequestParam注解是获取静态URL传入的参数
@PathVariable是获取请求路径中的变量作为参数
@GetMapping("update")
public void updateCategory(@RequestParam("id") Long id, @RequestParam("name") String name){
this.categoryService.updateCategory(id,name);
}
@GetMapping("bid/{bid}")
public ResponseEntity<List<Category>> queryByBrandId(@PathVariable("bid") Long bid){
List<Category> lists=this.categoryService.queryByBrandId(bid);
if (CollectionUtils.isEmpty(lists)){
return ResponseEntity.notFound().build();
}
return ResponseEntity.ok(lists);
}
本文详细解析了@RequestParam和@PathVariable注解在Spring MVC中的使用场景和区别。通过具体示例,阐述了如何利用这两个注解从HTTP请求中提取参数,为理解和应用Spring框架提供了实用指南。
5243

被折叠的 条评论
为什么被折叠?



