首页 > 编程语言 > 详细

Springboot接口注解PathVariable和RequestParam的区别

时间:2021-01-12 16:37:05      阅读:31      评论:0      收藏:0      [点我收藏+]

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

Springboot接口注解PathVariable和RequestParam的区别

原文:https://www.cnblogs.com/ddfly1/p/14266964.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!