Spring Cloud OpenFeign 创建动态查询参数失败 [英] Spring Cloud OpenFeign Failed to Create Dynamic Query Parameters

查看:28
本文介绍了Spring Cloud OpenFeign 创建动态查询参数失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Spring Cloud openFeign 无法创建动态查询参数.它抛出以下异常,因为 SpringMvcContract 试图找到不存在的 RequestParam 值属性.

Spring cloud openFeign can't create dynamic query parameters. It throws below exception because SpringMvcContract tries to find the RequestParam value attribute which doesn't exist.

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 不生成查询参数.

I tried using @QueryMap instead of @RequestParam but @QueryMap does not generate query parameters.

顺便说一句@RequestParam Mapparams 方法参数可以很好地生成动态查询参数.

Btw @RequestParam Map<String, Object> params method parameter works fine to generate a dynamic query parameter.

但是我想使用一个自定义对象,在这个对象中,feign 客户端可以根据对象的属性生成动态查询参数.

But I want to use a custom object in which the feign client can generate dynamic query parameters from the object's attributes.

推荐答案

来自 Spring Cloud OpenFeign 文档:

Spring Cloud OpenFeign 提供了一个等效的@SpringQueryMap注解,用于将POJO或Map参数注解为查询参数映射

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);

这篇关于Spring Cloud OpenFeign 创建动态查询参数失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆