feign中和controller中不一样的地方
controller中可以get方法使用对象参数无需任何注解,可默认绑定到对象!
示例代码如下:
@GetMapping(value =ClueClient.LIST_OPERATIONS)
public CrmResult<List<RysClueOperateBO>> getOperateLists(
@NotNull(message = "clueId必传") @PathVariable(name = "clueId") Long clueId,
RysClueOperateListQTO rysClueOperateListQTO) {
log.info("clueId:{},rysClueOperateListQTO:{}",clueId,JSON.toJSON(rysClueOperateListQTO));
}
public interface ClueClient {
String LIST_OPERATIONS = "/clues/{clueId}/operations";
@GetMapping(LIST_OPERATIONS)
CrmResult<List<RysClueOperateBO>> getOperateLists(@NotNull(message = "clueId")
@PathVariable(name = "clueId") Long clueId,
RysClueOperateListQTO rysClueOperateListQTO);
}
- spring mvc controller mapping 能自动装配参数到RysClueOperateQTO中。访问服务这个接口,能正常打印请求的参数。
- 但消费者通过feignclient 调用服务。服务不能正常打印参数。RysClueOperateQTO是空对象。
- 引入@SpringQueryMap注解解决问题。https://cloud.spring.io/spring-cloud-openfeign/reference/html/#feign-querymap-support
The OpenFeign @QueryMap
annotation provides support for POJOs to be used as GET parameter maps. Unfortunately, the default OpenFeign QueryMap annotation is incompatible with Spring because it lacks a value
property.
Spring Cloud OpenFeign provides an equivalent @SpringQueryMap
annotation, which is used to annotate a POJO or Map parameter as a query parameter map.