开发者

Leaving some {template} in builder URI with UriBuilder

Jersey UriBuilder can replace all the templates in a URI:

UriBuilder.fromResource(this.getClass()).path("{id}/{op}").build(12, "buy")

On the client side, it is exactly what we want ; On the server side, in some cases, we want to keep开发者_StackOverflow some templates unchanged (to inform the client that the URI depends on it, that it will have to fill it with values).

Building a URI without giving all template throws an exception. So, is there another way to leave some template unchanged?


I believe the proper way to do this is to call #toTemplate. This creates a template string. I believe that a URI that has unresolved template parameters is not valid. Here's an example:

UriBuilder.fromResource(this.getClass()).path("{id}/{op}").toTemplate();

This will preserve the template place holders.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜