过滤器链,拦截器链
public interface IHandler {
boolean doIt();
}
public class Handler1 implements IHandler {
@Override
public boolean doIt() {
System.out.println("handler 1");
return true;
}
}
public class Handler2 implements IHandler {
@Override
public boolean doIt() {
System.out.println("handler 2");
return true;
}
}
public class HandlerChain {
private List<IHandler> handlers = new ArrayList<>();
public void addHandler(IHandler handler) {
handlers.add(handler);
}
public void doHandlers() {
for (IHandler handler : handlers) {
boolean res = handler.doIt();
if (!res) {
break;
}
}
}
}
public class Client {
public static void main(String[] args) {
HandlerChain handlerChain = new HandlerChain();
handlerChain.addHandler(new Handler1());
handlerChain.addHandler(new Handler2());
handlerChain.doHandlers();
}
}
树下应用,挺多的。
① Struts2
的过滤器链
② Java web
的过滤器链
③ SpringMVC
的拦截器链
④ Dubbo
的过滤器链 参考文档 dubbo的filterhttps://blog.csdn.net/wjlucky262/article/details/105907579)
查看全部 浅谈模式 - 汇总篇