Jersey method selection by query parameters

后端 未结 3 1210
渐次进展
渐次进展 2021-01-23 03:14

I need to implement a webservice that uses the first query parameter to identify the operation, i.e. the client call would be something like: http://localhost:8080/ws/oper

3条回答
  •  温柔的废话
    2021-01-23 04:11

    I think method selection is based on the non parameter part of the URI. Can't you design this in a way the client invoke http://localhost:8080/ws/operation/info and http://localhost:8080/ws/operation/create?name=something instead?

    That would be easy to achieve:

    @Path("/operation")
    public class Operation {
    
        @GET 
        @Path("info")
        public String info() {
            return "info";
        }
    
        @GET 
        @Path("create")
        public String create(@QueryParam("name") String name) {
            return "create";
        }
    }
    

提交回复
热议问题