Spring Cloud openFeign无法创建动态查询参数。它抛出以下异常,因为SpringMvcContract尝试查找不存在的RequestParam值属性。
java.lang.IllegalStateException: RequestParam.value() was empty on parameter 0
@RequestMapping(method = RequestMethod.GET, value = "/orders")
Pageable<Order> searchOrder2(@RequestParam CustomObject customObject);
我尝试使用
@QueryMap而不是
@RequestParam,但
@QueryMap不会生成查询参数。
Btw
@RequestParam Map<String, Object> params方法参数可以很好地生成动态查询参数。
但是我想使用一个自定义对象,假冒客户端可以在其中从该对象的属性生成动态查询参数。
请您参考如下方法:
Spring Cloud OpenFeign provides an equivalent @SpringQueryMap annotation, which is used to annotate a POJO or Map parameter as a query parameter map
因此,您的代码应为:
@RequestMapping(method = RequestMethod.GET, value = "/orders")
Pageable<Order> searchOrder2(@SpringQueryMap @ModelAttribute CustomObject customObject);


