繁体   English   中英

从REST中的资源路径获取占位符值?

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM