Jfinal 3.5 中Route的使用方法

#1.configRoute的用法前端

public void configRoute(Routes me) { me.add("/hello", HelloController.class); //function1 me.add("/hello", HelloController.class,"");//function2 me.add("/",IndexController.class,"/views");//function3 } 注意: function1等價於function2,function3 中的最後一個參數,爲空或者不寫(指定爲/webapp),當參數存在時:webapp/views. #2.路由分包 指的是,將路由按照必定的規則分離,譬如最簡單的先後分離 ` public void configRoute(Routes me) {web

me.setBaseViewPath("/views");
  me.add(new FrontRoute());
  me.add(new AdminRoute()); 
}
`

前端路由與後端路由 `public class FrontRoute extends Routes {後端

[@Override](https://my.oschina.net/u/1162528)
public void config() {
	// TODO Auto-generated method stub
	setBaseViewPath("views");
     add("/front",IndexController.class);
}

' public class AdminRoute extends Routes {app

[@Override](https://my.oschina.net/u/1162528)
public void config() {
	// TODO Auto-generated method stub
   setBaseViewPath("views");
   add("/admin", AdminController.class);
}

}`webapp

3 RouteInteceptor

添加攔截器在路由,做爲controller的前置 `public class FrontRouteInterceptor implements Interceptor {ide

[@Override](https://my.oschina.net/u/1162528)
public void intercept(Invocation inv) {
	// TODO Auto-generated method stub
	System.out.println("我是攔截器,我被調用了");
      inv.invoke();//調用
}

} public void config() { // TODO Auto-generated method stub setBaseViewPath("views"); addInterceptor(new FrontRouteInterceptor());// add("/front",IndexController.class); }` .net

4路由規則

@ActionKey 打破controller規則code

  1. -- ControllerKey/method/v0-v1
  2. -- ControllerKey/Method
  3. -- Controllerkey/v0-v1
相關文章
相關標籤/搜索