[英]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.