Springboot接口注解PathVariable和RequestParam的区别

Get请求:

 

  • PathVariable用法:
@ApiOperation("手机号码归属地查询")
@RequestMapping(value = "/phoneAttributionQuery/{mobile}", method = RequestMethod.GET)
@ResponseBody
public Response phoneAttributionQuery(@PathVariable("mobile") String mobile){
try{
Response response = phoneNumberService.phoneAttributionQuery(mobile);
return response;
}catch(Exception e){
logger.error("手机号码归属地查询异常:{}", e);
return Response.error("手机号码归属地查询异常");
}
}
请求url>> http://localhost:9292/third/phoneApi/phoneAttributionQuery/1XXXXXX9539

  • RequestParam用法:
@ApiOperation("手机号码归属地查询")
@RequestMapping(value = "/phoneAttributionQuery", method = RequestMethod.GET)
@ResponseBody
public Response phoneAttributionQuery2(@RequestParam("mobile") String mobile){
try{
Response response = phoneNumberService.phoneAttributionQuery(mobile);
return response;
}catch(Exception e){
logger.error("手机号码归属地查询异常:{}", e);
return Response.error("手机号码归属地查询异常");
}
}
请求url>> http://localhost:9292/third/phoneApi/phoneAttributionQuery?mobile=1XXXXXX9539
posted @ 2021-01-12 14:54  李飞∮  阅读(123)  评论(0编辑  收藏  举报