Optional params in REST API request using Jersey 2.21

前端 未结 2 1476
眼角桃花
眼角桃花 2020-12-10 14:29

I\'m playing around with Jersey 2.21 and I\'d like to know if it\'s possible to have an \"optional\" param which can, or not, be present in the request made to

2条回答
  •  南笙
    南笙 (楼主)
    2020-12-10 14:37

    There is a way easier way to do this:

    @GET
    @Path("myMethod/{id}")
    public String myMethod(@PathParam("id") Integer id) {
    }
    
    @GET
    @Path("myMethod")
    public String myMethod() {
      return myMethod(null);
    }
    

    No tricky regex required.

提交回复
热议问题