Spring Cloud Feign Get请求传对象参数

前置说明,有A、B两个服务,A服务调用B服务,B服务接口是Get类型,接受参数对象

feign get请求传对象参数分两种情况

版本在2.1之前,则A服务使用Map map替代对象传给B服务

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//A-service
@ApiOperation(value = "查询xx", httpMethod = "GET")
@GetMapping("/maps")
public ReturnEntity getOrgPositionInMap(OrganizationMapQO organizationMapQO) {
HashMap map = new HashMap(BeanMap.create(organizationMapQO));
ReturnEntity returnEntity = sysLoginFeignClient.getOrgPositionInMap(map);
return returnEntity;
}

//feign-service
@ResponseBody
@GetMapping(value = "/organizations/maps", consumes = MediaType.APPLICATION_PROBLEM_JSON_UTF8_VALUE, produces = "application/json")
ReturnEntity getOrgPositionInMap(@RequestParam Map map);

//B-service
@ApiOperation(value = "查询xx", httpMethod = "GET")
@GetMapping("/maps")
public List<OrganizationMapVO> getOrgPositionInMap(OrganizationMapQO organizationMapQO) {
return sysDeptService.getOrgPositionInMap(organizationMapQO);
}

版本在2.1之后,在feign-service中使用@SpringQueryMap

1
2
3
4
//feign-service
@ResponseBody
@GetMapping(value = "/organizations/maps", consumes = MediaType.APPLICATION_PROBLEM_JSON_UTF8_VALUE, produces = "application/json")
ReturnEntity getOrgPositionInMap(@SpringQueryMap OrganizationMapQO organizationMapQO);

Powered by AppBlog.CN     浙ICP备14037229号

Copyright © 2012 - 2021 APP开发技术博客 All Rights Reserved.

访客数 : | 访问量 :