目录
- 一、控制器
- 二、Feign客户端
openFeign调用接口时传递Json参数以及httpservletrequest对象
一、控制器
@RestController
@RequestMapping("test")
public class TestController {/*** 用来测试表单参数传递:单个参数*/@PostMapping(value = "/formDataTest")public Object formDataTest(@RequestParam String id) {......}/*** 用来测试表单参数传递:多个参数*/@PostMapping(value = "/formDataTest2")public Object formDataTest2(@RequestParam String id, @RequestParam String name) {......}/*** 用来测试Json参数传递*/@PostMapping(value = "/jsonTest")public Object jsonTest(@RequestBody JsonTestParam param) {......}/*** 用来测试HttpServletRequest参数传递*/@PostMapping(value = "/httpServletRequest_Test")public Object httpServletRequest_Test(HttpServletRequest request) {......}
}
二、Feign客户端
@FeignClient(name = "defaultXXX-cloud", contextId = "XXXClient", path = "defaultXXXPath")
@RefreshScope
public interface XXXFeignClient {/*** 传递表单参数:单个参数*/@PostMapping(value = "/test/formDataTest")Object formDataTest(String id);/*** 传递表单参数:多个参数,需要使用@RequestParam并指定name属性,否则会报错*/@PostMapping(value = "/test/formDataTest2")Object formDataTest2(@RequestParam(name = "id") String id, @RequestParam(name = "name") String name);/*** 传递JSON参数方式一:指定:consumes = "application/json"*/@PostMapping(value = "/test/jsonTest", consumes = "application/json")Object jsonTest(JsonTestParam param);/*** 传递JSON参数方式二:使用@RequestBody*/@PostMapping(value = "/test/jsonTest")Object jsonTest(@RequestBody JsonTestParam param);/*** 传递HttpServletRequest:不需要传递,直接调用即可*/@PostMapping(value = "/test/httpServletRequest_Test")Object httpServletRequest_Test();}