Java apachecommons链基本示例
我需要进入一个项目的Apaches公共链。所以我试着让一个基本的例子在下面运行: Commons链通过Maven安装 我编写了以下链库:Java apachecommons链基本示例,java,maven,apache-commons,Java,Maven,Apache Commons,我需要进入一个项目的Apaches公共链。所以我试着让一个基本的例子在下面运行: Commons链通过Maven安装 我编写了以下链库: public class PFChain extends ChainBase { public PFChain() { super(); addCommand(new CalcE()); addCommand(new CalcDOEB()); addCommand(new CalcG())
public class PFChain extends ChainBase {
public PFChain() {
super();
addCommand(new CalcE());
addCommand(new CalcDOEB());
addCommand(new CalcG());
}
public static void executePFChain() {
Command process = new PFChain();
Context context = new ContextBase();
try {
process.execute(context);
} catch (Exception e) {
System.out.println("errortext");
e.printStackTrace();
}
}
}
我的三个命令类如下所示:
public class CalcDOEB implements Command {
@Override
public boolean execute(Context context) throws Exception {
System.out.println("Calculating DOEB...");
return true;
}
}
public class CalcE implements Command {
@Override
public boolean execute(Context context) throws Exception {
System.out.println("Calculating E");
return true;
}
}
public class CalcG implements Command {
@Override
public boolean execute(Context context) throws Exception {
System.out.println("Calculation G...");
return true;
}
}
现在奇怪的是,他只执行链中的第一个命令。
它们都可以工作,但前提是它们位于命令列表的最前面
当我打开调试器时,我看到它们都在列表中
此错误来自何处,如何修复?
您好
Nicolas尝试将所有返回语句更改为
false
,而不是true
。
当您返回true时,就结束了链。因为不希望链结束,所以需要返回false
要了解更多信息,请查看Javadoc:
你我的朋友是上帝:)谢谢你。