[英]Getting place holder value from resource path in REST?
我正在使用Jersey RESTful Web服務。 我有以下資源。
@Path("/banker/{location}")
@Component
public class BankResource{
@GET
@Path("/{id}")
@Produces({MediaType.APPLICATION_XML})
@Override
public Response getBankerByID(@PathParam("id") String id) {
//some logic
}
}
在上述課程中,我如何獲得{location}的值? 因為基於{location}值,我需要進行一些處理。 是否有可能獲得其價值?
謝謝!
您可以使用@PathParam獲取位置值,並將其映射到方法參數,如下所示。 `
@Path("/banker/{location}")
@Component
public class BankResource{
@GET
@Path("/{id}")
@Produces({MediaType.APPLICATION_XML})
@Override
public Response getBankerByID(@PathParam("location") String location,
@PathParam("id") String id) {
//your code here
}
`
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.