java 注释 超链接,Java的球衣声明超链接@Ref使用注释

I have been trying to expand upon the example provided in Chapter 6 (Declarative Hyperlinking) of the Jersey 1.12 documentation but appear to have hit a wall with regard to the use of the @Ref annotation.

My code is as follows:

@Path("/offerings/{offeringId}/widgets")

@Produces(MediaType.APPLICATION_JSON)

public class WidgetsResource {

@GET

@Path("/{widgetId}")

public Response get(@PathParam("offeringId") String offeringId, @PathParam("widgetId") String widgetId) {

Widgets widgets = new Widgets();

widgets.setOfferingId(Integer.valueOf(offeringId));

Widget widget = new Widget();

widget.setId(Integer.valueOf(widgetId));

widgets.setWidgets(Arrays.asList(widget));

return Response.status(200).entity(widgets).build();

}

}

public class Widgets {

@Ref(resource = WidgetsResource.class, style=Style.ABSOLUTE)

URI uri;

@JsonIgnore

private int offeringId;

private Collection widgets;

public Collection getWidgets() {

return widgets;

}

public void setWidgets(Collection widgets) {

this.widgets = widgets;

}

public URI getUri() {

return uri;

}

public int getOfferingId() {

return offeringId;

}

public void setOfferingId(int id) {

this.offeringId = id;

}

}

public class Widget {

@Ref(resource = WidgetsResource.class, style=Style.ABSOLUTE, bindings={

@Binding(name="offeringId", value="${entity.offeringId}")}

)

URI uri;

private int id;

public URI getUri() {

return uri;

}

public int getId() {

return id;

}

public void setId(int id) {

this.id = id;

}

}

This works fine for the URL generated for an instance of the Widgets collection object:

"uri": "http://localhost:65080//offerings/9999/widgets"

However, I want to know how I can append the id of the Widget instances within the Collection to the URL for each Widget. So,the URI generated would be something like:

"uri": "http://localhost:65080//offerings/9999/widgets/1234"

I can't seem to find a way of using the Ref annotation to achieve this without starting to hardcode the whole path value within the Widget class, which I'd like to avoid if possible.

Is there a standard way of achieving this?

解决方案

My reading of that documentation says you could do something like this (untested!):

@Ref(value="/offerings/{offeringId}/widgets/{widgetId}", style=ABSOLUTE)

URI uri;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值