我有一个类,这样注释@Path如下:
@Path("widgets")
@Produces(MediaType.APPLICATION_XML)
public class WidgetResource {
@GET
public Response getWidgets(@QueryParam("limit"))
{
//This class returns the plural noun, a list of widgets
//...}
@GET
@Path("widget/{id}")
public Response getWidgetById(@PathParam("id") long id)
{
//This class returns a single widget by id
//...}
Run Code Online (Sandbox Code Playgroud)
当我启动测试客户端时,localhost/widgets按预期映射,但是当getWidgetById方法映射到时localhost/widgets/widget/{id}.这不是我想要的 - 我想拥有localhost/widgets and localhost/widget/{id}
我已经尝试@Path在类级别省略注释,但这会阻止Jersey将此类识别为REST资源(我尝试了两者ScanningResourceConfig并且ClassNameResourceConfig- 无法将类加载为资源,除非@Path在类级别存在).
我猜一个(丑陋的)解决方法是将WidgetResource类和WidgetsResource类之间的方法分开.我认为这是一个糟糕的解决方案,因为这两种方法在同一个类中共享资源,但我确实需要REST-ful localhost/widget(对于单个实体)和localhost/widgets(对于复数).
我错过了什么 - 如果我只是@Path注释方法(我无法让它工作),我有什么办法让泽西拿起这个类作为资源类,如果不是我可以强制绝对映射(@Path(/widget/{id}))或一些相对映射(@Path(../widget/id) …