How to custom QueryMapEncoder when using annotation @QueryMap to construct a query in Feign

当使用Feign调用下游服务时,可能需要在URL中传递多个查询参数。如果参数较少,可以使用@Param注解传递。但参数多时,代码会变得复杂。一种解决方案是使用@QueryMap从映射中构造查询参数,但这种方式不够友好且可读性差。另一种更好的方式是通过QueryMapEncoder从POJO对象生成查询参数,提高代码的可读性和组织性。
摘要由CSDN通过智能技术生成

When we use Feign to call downstream services, we may need to pass several query parameters in URL. If there are just one or two query parameters, we can use annotation @Param to pass the value of the quey parameters.

@RequestLine("GET /repos?owner={owner}&repo={repo}")
List<Contributor> getContributors(@Param("owner") String owner, @Param("repo") String repo);

But if there are many query parameters, the code will look a little complicated.

@RequestLine("GET /repos?owner={owner}&repo={repo}&branches={branches}&commitStartDate={commitStartDate}&commitEndDate={commitEndDate}")
List<Contributor> getContributors(@Param("owner") String owner,
                                  @Param("repo") String repo,
                                  @Param("branches") String branches
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值