2017-10-18 11:36
@jFinal老四 jfinal 就是这样一步步迭代式发展的,通过大家的反馈不断改进,同时还要保持架构的优雅,以及对前面版本的兼容性
2017-10-18 11:19
做个 hanlder 跳过 servlet 即可:
public class SkipSerlvetHandler extends Handler {
public void handle(target, req, res, isHandled) {
if (target.startswith(servlet前缀)) {
return ;
}
next.handle(target, req, res, isHandled);
}
}
跳过后时候除了可以用 startswith 还可以用正则,根据你的实际情况来选择,最后再添加上这个 handler:
me.add(new SkipServletHandler());
2017-10-17 18:09
@liujh 你是指 struts2 中的 ActionContext.getContext().getSession() 这种用法吧,在 jfinal 中用一个 ThreadLocal 配合一个全局拦截器很容易:
public class Context implements Interceptor {
private static final ThreadLocal TL = new ThreadLocal();
public class intercept(Invocation inv) {
TL.set(inv.getController().getSession());
try {
inv.invoke();
}finally {
TL.remove();
}
}
public static Sessoin getSession() {
return TL.get();
}
}
最后配置这个为全局拦截器即可:
public void configInterceptor(Interceptors me) {
me.add(new Context());
}
然后你就可以在 service 中这样用来了:
Session session = Context.getSession();