本文介绍了Feign Client无法解析查询参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的界面.

public interface SCIMServiceStub {

    @RequestLine("GET /Users/{id}")
    SCIMUser getUser(@Param("id") String id);

    @RequestLine("GET /Groups?filter=displayName+Eq+{roleName}")
    SCIMGroup isValidRole(@Param("roleName") String roleName);

}

在这里getUser调用正常.但是isValidRole不能正常工作,因为最终会这样发送请求.

Here getUser call works fine. But isValidRole is not working properly as the request is eventually sent like this.

/Groups?filter=displayName+Eq+{roleName}"

此处{roleName}无法解析.我在这里想念什么?谢谢您的帮助,因为我对此一无所知.

Here {roleName} is not resolved. What am I missing here? Appreciate some help, as I'm clueless at this point.

修改:还有1个问题:是否可以避免自动对查询参数进行网址编码?

Edit: 1 more question: Is there a way to avoid automatic url encoding of query parameters?

推荐答案

这似乎是由已打开的错误引起的- https://github.com/OpenFeign/feign/issues/424

It seems to be caused by a bug that is already opened - https://github.com/OpenFeign/feign/issues/424

就像在评论中一样,您可以定义自己的Param.Expander如下所示.

Like in comments, you can define your own Param.Expander something like below as a workaround.

@RequestLine("GET /Groups?filter={roleName}")
String isValidRole(@Param(value = "roleName", expander = PrefixExpander.class) String roleName);

static final class PrefixExpander implements Param.Expander {
    @Override
    public String expand(Object value) {
        return "displayName+Eq+" + value;
    }
}

这篇关于Feign Client无法解析查询参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 23:45