1. 引入依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
2.写客户端去请求
@RequestMapping(value = "space/list", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
Result<List<SFlatInfoDto>> getFlatList(
@RequestBody SFlatInfoDto dto
);
- method 什么类型,POST还是GET
- MediaType 参数以什么方式去请求
- SFlatInfoDto 传递的参数对象
3.在客户端上加注解
@FeignClient(url = "${fegin-inter-api.flatUrl}", name = "flatUrl")
- fegin-inter-api.flatUrl 在配置文件里面写着,例如http:demo/
那么你请求的,就是http:demo/space/list - name 全局唯一,不能在别的client里面重复,不然会报错
4.action里面调用
@Autowired
private SFlatInfoFeign sFlatInfoFeign;
sFlatInfoFeign.getFlatList(sFlatInfoDto);