configRoute(Routes me)
This method is used to configure JFinal access routing. The following code configures the mapping of "/hello" to the HelloController controller. Through the following configuration, http://localhost/hello will access HelloController.index() method, and http://localhost/hello/methodName will access the HelloController.methodName() method.
{ me.add("/hello",
HelloController.class);
Routes class mainly includes The following two methods:
public Routes add(String controllerKey, Class<? extends Controller>
controllerClass, String viewPath)
public Routes add(String controllerKey, Class<? extends Controller>
##controllerClass)
##From the table It can be seen that JFinal accesses an exact Action (see Section 3.2 for Action definition) and needs to use controllerKey and method to accurately locate it. When method is omitted, the default value is index. urlPara is to carry parameter values in the url. urlPara can carry multiple values in one request at the same time. JFinal uses the minus sign "-" to separate multiple values by default (the separator can be set through constants.setUrlParaSeparator(String)), In Controller, these values can be retrieved separately through getPara(intindex). The three parts of controllerKey, method, and urlPara must be separated by forward slashes "/". Note that the controllerKey itself can also contain a forward slash "/", such as "/admin/article", which essentially implements the namespace function of struts2.
JFinal also provides ActionKey annotations in addition to the above routing rules, which can break the original rules. The following is a code example:
{ render("login.html");
}
Assume that the controllerKey value of UserController is "/user". After using the @ActionKey("/login") annotation, the actionKey changes from the original "/user/login" to " /login". This annotation can also allow characters such as minus signs or numbers to be used in actionKey, such as "/user/123-456".
JFinal routing can also be split and configured, which is particularly useful for large-scale team development. The following is a code example:
public void config(){
add("/",IndexController.class);
add("/blog", BlogController.class);
}
}
public void config(){
add("/admin",AdminController.class);
add("/admin/user", UserController.class );
}
}
publicvoid configRoute(Routesme)
{ me.add(new FrontRoutes()); // Front-end routing
me.add(new AdminRoutes()); / / Backend routing
}
##public void configConstant(Constantsme) {}
public void configPlugin(Pluginsme) {}
public void configInterceptor(Interceptorsme) {}
##public void configHandler(Handlersme) {}
}