string boot中get、post 接口

后端接口:

1.get,调用方式 http://127.0.0.1:8088/xxxx/{id}

代码如下:

1 /**
2      * get方式
3      */
4     @RequestMapping(value = "/xxxxx/{id}", method = RequestMethod.GET)
5     public Object xxxxx(@PathVariable int id) {
6         //以下是逻辑处理
7 
8         return xxx;
9     }
View Code

2.post

1)调用地址 http://127.0.0.1:8088/xxxx ,入参格式 application/json,{"a":111,"b":"aa"}

 代码如下:

 1 /**
 2      * post方式
 3      */
 4     @RequestMapping(value = "/xxxxx", method = RequestMethod.POST)
 5     public Object xxxxx(@RequestBody HashMap<String, String> map)
 6     {
 7         System.out.println("map:"+map);
 8 
 9         //以下是逻辑处理
10         
11 
12         return xxxx;
13     }
View Code

2)调用地址 http://127.0.0.1:8088/xxxx ,入参格式 application/form-data 格式 :phone: "18295880001", env: "dev"

 代码如下:

 1 /**
 2      * post方式
 3      */
 4     @RequestMapping(value = "/xxxxx", method = RequestMethod.POST)
 5     public Object xxxxx(@RequestParam(value = "xxx", required = true) String xxx,
 6         @RequestParam(value = "env", required = xxx) String xxx)
 7     {
 8         //以下是逻辑处理
 9 
10         return xxxxx;
11     }
View Code
原文地址:https://www.cnblogs.com/whycai/p/14090375.html