SpringBoot框架使用(两种携带参数的get接口开发)
SpringBoot框架使用(两种携带参数的get接口开发)
简单随风 2018-05-31 13:59:47 9588 收藏 3
分类专栏: SpringBoot
版权
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;
}
1
2
3
4
5
6
7
8
9
10
11
运行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;
}
1
2
3
4
5
6
7
8
9
10
Rerun Application,然后浏览器访问http://localhost:9527/get/with/param/1/2
————————————————
版权声明:本文为CSDN博主「简单随风」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/lt326030434/article/details/80523283