|
DeveloperMapping
How to handle URL
zh-Hans , en Handle URLAs you see, WebWind does not require any particular interface, and allows multiple methods put together in one class. Each method can handle one URL defined by @Mapping annotation. The method you defined to handle URL must have following requirements:
Method can throw any type of exception. Definition of URLWebWind uses regular expression to handle URL internally. However, regular expression is not easy to write correctly. So the definition of URL in WebWind uses human-readable format like /user/$1/$2.html. When you define the URL with parameters, WebWind can pass these parameters to the method as arguments. The placeholder of parameters in URL is $, and its index starts from 1, maximum to 9, which means you can pass at most 9 parameters. Each $n (n=1 to 9) will match the particular group of URL. It may match the empty string, but it does NOT match any string contains /, which means: /user/$1.html will match /user/123456.html, but not match /user/123/456.html. Such definitions of URL are invalid:
Such definitions of URL are valid but not recommended:
Parameters in URL will automatically converted to the actual types of arguments in method. For example: @Mapping("/user/$1/$2.html")
public void handle(long userId, int postId) throws Exception {
// $1 is converted to long, $2 is converted to int...
}Supported Types of ArgumentsNot all the Java types of arguments of method can be supported, because WebWind must convert the string to the particular Java type of argument. The build-in supported types are java.lang.String and all primitive types as well as its wrapper types (int, Integer, boolean, Boolean, etc.).
TODO: How to add more types | |||||||||||||||||||||||||||||||