0
点赞
收藏
分享

微信扫一扫

@PathVariable和@RequestParam的区别

有点d伤 2022-10-11 阅读 218


@PathVariable用来获取URL路径中的变量

@RequestParam用来获取请求变量

eg:

localhost:8080/v1/users/111?attributeName=USER_ACCOUNT

获取以上请求路径中的111使用@PathVariable

获取attributeName变量使用@RequestParam

注意:

@GetMapping("/{attributeValue}")
@ResponseBody
public ReturnResult select(@PathVariable String attributeValue,
@RequestParam(required = false) String attributeName) throws

只有设置了@RequestParam(required = false)时,即使没有attributeName这个变量也会进入到此方法,若required=true时,缺少此参数是不会进入到这个方法的,默认为true


举报

相关推荐

0 条评论