[英]Migrate builder to Spring hateoas 2.6.7
我在 hatoas:1.0 中實現了這個舊代碼
public class StaticPathLinkBuilder extends LinkBuilderSupport<StaticPathLinkBuilder> {
@Override
protected StaticPathLinkBuilder createNewInstance(UriComponentsBuilder builder) {
return new StaticPathLinkBuilder(builder);
}
我將代碼更新為 hatoas 2.6.7,但代碼是這樣更改的:
public class StaticPathLinkBuilder extends LinkBuilderSupport<StaticPathLinkBuilder> {
@Override
protected StaticPathLinkBuilder createNewInstance(UriComponents components, List<Affordance> affordances) {
return null;
}
實施此更改的正確方法是什么? 我試過這個:
@Override
protected StaticPathLinkBuilder createNewInstance(UriComponents components, List<Affordance> affordances) {
return new StaticPathLinkBuilder(UriComponentsBuilder.newInstance().uriComponents(components));
}
但目前尚不清楚我必須如何實現我可以發送affordances
的代碼。
你能建議什么是實現這一點的正確方法嗎?
正如您在其源代碼中看到的那樣, LinkBuilderSupport
已經提供了一個帶有兩個必需參數UriComponents
和List<Affordance>
的構造函數。
在自己的庫代碼庫中,不同的LinkBuilder
實現如BasicLinkBuilder
或TemplateVariableAwareLinkBuilderSupport
已經在其實現中利用了這一事實。
在您的用例中,您可以嘗試類似的方法:
public class StaticPathLinkBuilder extends LinkBuilderSupport<StaticPathLinkBuilder> {
private StaticPathLinkBuilder(UriComponents components, List<Affordance> affordances) {
super(components, affordances);
}
@Override
protected StaticPathLinkBuilder createNewInstance(UriComponents components, List<Affordance> affordances) {
return new StaticPathLinkBuilder(components, affordances);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.