SpringCloud Feign Get请求传对象参数

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

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

  • 1.版本在2.1之前,如我springboot是2.0.6.RELEASE,springcloud是Finchley.SR2版本,则A服务使用Map map替代对象传给B服务
//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.版本在2.1之后,在feign-service中使用@SpringQueryMap
//feign-service
@ResponseBody
@GetMapping(value = "/organizations/maps", consumes = MediaType.APPLICATION_PROBLEM_JSON_UTF8_VALUE, produces = "application/json")
ReturnEntity getOrgPositionInMap(@SpringQueryMap OrganizationMapQO organizationMapQO);

你可能感兴趣的:(SpringCloud实战,SpringBoot,项目开发)