REST how to pass empty path parameter?

后端 未结 2 1061
刺人心
刺人心 2021-02-05 13:12

I\'m building REST web app using Netbean 7.1.1 Glassfish 3.1.2

I have 2 URL:

\"http://myPage/resource/getall/name\"  (get some          


        
相关标签:
2条回答
  • 2021-02-05 13:45

    You can specify a regular expression for your Path Parameter (see 2.1.1. @Path).

    If you use .* matches both empty and non empty names So if you write:

    @GET
    @Path("getall/{name: .*}")
    @Produces("application/json")
    public Object Getall(@PathParam("name") String customerName) {
          //here I want to call SQL if customerName is not null. is it possible???
    }
    

    it will match both "http://myPage/resource/getall" and "http://myPage/resource/getall/name".

    0 讨论(0)
  • 2021-02-05 14:00
    @GET
    @Path("getall{name:(/[^/]+?)?}")
    @Produces("application/json")
    public Object Getall(@PathParam("name") String customerName) {
      //here I want to call SQL if customerName is not null. is it      
    
     possible??? 
      }
    
    0 讨论(0)
提交回复
热议问题