Java RestBuilder编码错误?

Java RestBuilder编码错误?,java,rest,uri,resteasy,Java,Rest,Uri,Resteasy,我试图使用RestEasy中的UriBuilder从字符串url创建URI,但得到了一些意想不到的结果。我正在运行下面的代码 UriBuilder UriBuilder=UriBuilder.fromPath(“http://localhost:8190/items?pageNumber={pageNumber}&pageSize={pageSize}”) System.out.println(uriBuilder.build(1,10)) 预期结果: http://localhost:8190

我试图使用RestEasy中的UriBuilder从字符串url创建URI,但得到了一些意想不到的结果。我正在运行下面的代码

UriBuilder UriBuilder=UriBuilder.fromPath(“http://localhost:8190/items?pageNumber={pageNumber}&pageSize={pageSize}”)

System.out.println(uriBuilder.build(1,10))

预期结果:

http://localhost:8190/items?pageNumber=1&pageSize=10

实际结果:

http://localhost:8190/items%3FpageNumber=1&pageSize=10

当使用UriBuilder.fromUri()而不是fromPath()时,它会在创建URI时引发异常

索引39处的查询中存在非法字符:http://localhost:8190/items?pageNumber={pageNumber}&pageSize={pageSize}

39处的字符是{

我不想解析完整的字符串来逐部分创建URI

我查看了RestEasy代码,它在使用org.jboss.RestEasy.util.Encode创建生成器时对“?”字符进行编码,使用org.jboss.RestEasy.util.Encode中的pathEncoding映射进行编码

我的用法不正确还是实现不正确?

因为是JAX-RS实现,来自Oracle of
fromPath

创建一个表示从URI路径初始化的相对URI的新实例

我认为它不是用于绝对URL的,因此我担心答案是您的用法不正确

您将需要这样的东西(尽管没有测试)


是的,这种方法很有效。谢谢!这不是绝对或相对URL,只是如果有查询参数,问号也会被编码,它不起作用。
UriBuilder.fromUri("http://localhost:8190/").
  path("{a}").
  queryParam("pageNumber", "{pageNumber}").
  queryParam("pageSize", "{pageSize}").
  build("items", 1,10);