문제

I have to following URI which outputs categories and subcategories:

Pattern:

www.uri.com/webservice/category1/category2/category3/category4

Example:

www.uri.com/webservice/1/56/104/605

This URI can have none,one or more subcategories like in the example. How do i get these parameters (1,56,104,605) in an array so i can check if each category is a subcategory of the other?

도움이 되었습니까?

해결책

Inject an UriInfo instance in your resource method and use the getPathParameters() or getPathSegments() method:

@Path("category/{categoryIds:.+}/product/{productId}")
public ReturnType myMethod(@Context UriInfo uriInfo) {

    for (PathSegment pathSegment: uriInfo.getPathSegments()) {
        //do here what you want with the uriInfo
    }
} 
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top