2017-11-14 15:55
新建一个Interceptor:
public class CookieInViewInterceptor implements Interceptor{
@Override
public void intercept(Invocation inv) {
Controller c = inv.getController();
//从cookie中取出属性值,放到当前Controller的request
c.setAttr("styleCode", c.getCookie("styleCode", "default"));
inv.invoke();
}
}
然后在JfinalConfig中加入全局拦截器:
public void configInterceptor(Interceptors me) {
// TODO Auto-generated method stub
me.add(new CookieInViewInterceptor());
}