get请求携带参数一般有两种方式:第一种是url?key1=value1&key2=value2,第二种是url/value1/value2,所以两种方式分开来讲
1.url?key1=value1&key2=value2
@RequestMapping(value = "/get/with/param",method = RequestMethod.GET)
public Map<String,Integer> getList(@RequestParam Integer start,
@RequestParam Integer end){
Map<String,Integer> myList =new HashMap<>();
myList.put("鞋",400);
myList.put("衬衫",300);
myList.put("T恤",200);
return myList;
}
运行Application,然后浏览器访问http://localhost:9527/get/with/param?start=1&end=2
2.url/value1/value2
@RequestMapping(value = "/get/with/param/{start}/{end}",method = RequestMethod.GET)
public Map myGetList(@PathVariable Integer start,
@PathVariable Integer end){
Map<String,Integer> myList =new HashMap<>();
myList.put("鞋",400);
myList.put("衬衫",300);
myList.put("T恤",200);
return myList;
}
Rerun Application,然后浏览器访问http://localhost:9527/get/with/param/1/2