编写需要参数才能访问的get请求
使用参数就要用到@RequestParam 参数类型 参数变量
,可以有多个参数
这个接口还是在MyGetMethod
类里面编写方法,有两种方法
第一种url:key=value&&key=value
:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
@RequestMapping(value = "/get/with/param", method = RequestMethod.GET) @ApiOperation(value = "需要参数才能访问的get请求的第一种实现方法", httpMethod = "GET") public Map<String, Integer> getList(@RequestParam Integer start, @RequestParam Integer end){
Map<String, Integer> myList = new HashMap<>();
myList.put("鞋",400); myList.put("电脑",5000); myList.put("手机",3500);
return myList;
}
|
方法二url: ip:port/get/with/param/10/20
:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
@RequestMapping(value = "/get/with/param/{start}/{end}", method = RequestMethod.GET) @ApiOperation(value = "需要参数才能访问的get请求的第二种实现方法", httpMethod = "GET") public Map<String,Integer> myGetList(@PathVariable Integer start, @PathVariable Integer end){
Map<String, Integer> myList = new HashMap<>();
myList.put("鞋",400); myList.put("电脑",5000); myList.put("手机",3500);
return myList; }
|