简体   繁体   中英

How to specify path annotation in rest api java to accept any path?

I am using jersey rest service in java to accept request.

Here is my snippet

    @Path("main")
    public class xxxx{
      @GET
      @Path("test/{path}")
      public void test(@Context HttpServletRequest req ) {
         System.out.println(req.getRequestURI());
      }
    }

I am invoking this using REST Api as test/abcd , it is working. I want @path to accept test/abcd or test/abcd/ab and so. I tried with "test/{path}/*" nothing works.

Please someone help me as I am new to this.

You should use regex in the @Path for example :

@Path("{parameter: .*}")
Response getData(@PathParam("parameter") List<String> parameter){
     //do processing
}

For more details you can see the examples given here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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