参考:https://cloud.tencent.com/developer/article/1414464 http://www.cocoachina.com/articles/33133#cocoachina0 先看用例: @RestController public class TestController { @RequestMapping( "/test/{inputJson}/{name}" ) @ResponseBody publ
参考:https://cloud.tencent.com/developer/article/1414464
http://www.cocoachina.com/articles/33133#cocoachina0
先看用例:
@RestController public class TestController { @RequestMapping("/test/{inputJson}/{name}") @ResponseBody public String test(@PathVariable String inputJson, @PathVariable String name){ System.out.println(inputJson); System.out.println(name); return inputJson; } @RequestMapping("/test2") @ResponseBody public String test2(@RequestBody String inputJson){ System.out.println(inputJson); return inputJson; } @RequestMapping(value = "/test3", method = RequestMethod.POST) @ResponseBody public String test3(String inputJson){ System.out.println(inputJson); return inputJson; } }
一、@PathVariable
这是restful风格的注解
请求格式如下:
http://localhost:8080/test/a/b
inputJson对应的值为a
named对应值为b
url后面输入什么值后台对应的就是什么,如果改为http://localhost:8080/test/b/a那么两个参数的值也会互换
注意:test后面必须有/*/*/这的格式,否则请求无效
二、@RequestBody
请求格式如下: