public static Link of(String href) {
return new Link(href);
}
public static Link of(String href, String relation) {
return new Link(href, relation);
}
public static Link of(String href, LinkRelation relation) {
return new Link(href, relation);
}
可以传入href和relation来构建一个Link对象。
看下面的例子:
Link link = Link.of("/something");
link = Link.of("/something", "my-rel");
public static Link of(UriTemplate template, String relation) {
return new Link(template, relation);
}
public static Link of(UriTemplate template, LinkRelation relation) {
return new Link(template, relation);
}
UriTemplate是对URI模板的封装,我们看一个使用的例子:
Link link = Link.of("/{segment}/something{?parameter}");
Map<String, Object> values = new HashMap<>();
values.put("segment", "path");
values.put("parameter", 42);
assertThat(link.expand(values).getHref())
.isEqualTo("/path/something?parameter=42");
Link link = Link.of("/some-resource"), IanaLinkRelations.NEXT);
assertThat(link.getRel()).isEqualTo(LinkRelation.of("next"));
assertThat(IanaLinkRelation.isIanaRel(link.getRel())).isTrue();