/java/

@Path Annotation And Regular expression

2015-07-23 22:35:12

From docs: By default, the URI variable must match the regular expression "[^/]+?". This variable may be customized by specifying a different regular expression after the variable name.

How to customize it ?, let see...

package pl.btbw;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;

@Path("/")
public class MyCtrl {

    @GET
    @Path("uppercase/{message: [A-Z]*}")
    public String uppercase(@PathParam("message") String message) {
        System.out.println("message: " + message);
        return message;
    }

    @GET
    @Path("lowercase/{message: [a-z]*}")
    public String lowercase(@PathParam("message") String message) {
        System.out.println("message: " + message);
        return message;
    }

    @GET
    @Path("uppercaseThenLowercase/{message: [A-Z]*[a-z]*}")
    public String uppercaseThenLowercase(@PathParam("message") String message) {
        System.out.println("message: " + message);
        return message;
    }
}

as you can imagine if you do not meet the url pattern you will revise 404 GitHub