【问题标题】:Getting place holder value from resource path in REST?从 REST 中的资源路径获取占位符价值?
【发布时间】:2014-01-09 13:38:33
【问题描述】:

我正在使用 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} 值我需要做一些处理。有没有可能得到它的价值?

谢谢!

【问题讨论】:

    标签: java web-services rest java-ee-7


    【解决方案1】:

    您可以使用@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
    }
    

    `

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-12-09
      • 2012-10-03
      • 1970-01-01
      • 2021-06-04
      • 1970-01-01
      • 2019-10-27
      • 2011-09-12
      • 2017-05-17
      相关资源
      最近更新 更多