常用请求方式:http://localhost:10003/railway-api/base/stEstimate/info?id=1
rest请求方式:
传统@RequestParam是从request 中接收请求!而 @PathVariable
是从一个URI模板里面来填充
拿一个例子来说吧
@RequestMapping(value = "/info/{id}", method = {RequestMethod.GET})public R info(@PathVariable("id") Long id) {StEstimate stEstimate = stEstimateService.getById(id);return R.ok().put("info", stEstimate);}
当我们访问请求 http://localhost:10003/railway-api/base/stEstimate/info/1 可以直接取到地址里面的参数1
{"msg": "success","code": 0,"info": {"id": 1,"title": "各种受力工具和绝缘工具应有产品合格证并定期进行试验,作好记录,特殊情况可以使用试验不合格或超过试验周期的工具。","sourceId": 48,"answ": "0","star1": "1","star2": "1","star3": "1","star4": "1","zyxzz": "0","zyjsry": "0","zyglry": "0"}
}
总体来说直接获取 URI 里的值还是很方便,不用去 request 里获取固定参数,如果只是 ID 这种单个或者多个数字字母,可以直接使用 @PathVariable 。