 
2017-03-29 14:53
应该这么写:
public class CatChildren extends Directive {
	public void setExprList(ExprList exprList){
		super.setExprList(exprList);		
	}
	@Override
	public void exec(Env env, Scope scope, Writer writer) {
		Object[] ret = this.exprList.evalExprList(scope);
		System.out.println("ret:"+ret[0]);
		//this.exprList.getExprArray()[0]为前台传入第一个参数
		String sql = "select c.* from mall_cat c where c.cat_level = " 
				+  ret[0] 
				+ " limit " 
				+ ret[1];
		System.out.println("catchildren_sql:"+sql);
		List list = MallCat.dao.find(sql);
		scope.setGlobal("catChildrenList", list);
	}	
	public boolean headEnd(){
		return true;
	}
}
 
2017-03-29 14:32
执行后,输出的sql语句为:
catchildren_sql:select c.* from mall_cat c where c.cat_level = com.jfinal.template.expr.ast.Field@27f8040d limit 3
所以会报错:
2017-03-29 14:28:31
[ERROR]-[Thread: qtp615634843-28]-[com.jfinal.core.ActionHandler.handle()]: /
com.jfinal.render.RenderException: com.jfinal.plugin.activerecord.ActiveRecordException: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.expr.ast.Field@27f8040d limit 3' at line 1
 
2017-03-29 14:31
我后台是这么写的
public class CatChildren extends Directive {
	public void setExprList(ExprList exprList){
		super.setExprList(exprList);		
	}
	@Override
	public void exec(Env env, Scope scope, Writer writer) {
		
		//this.exprList.getExprArray()[0]为前台传入第一个参数
		String sql = "select c.* from mall_cat c where c.cat_level = " 
				+  this.exprList.getExprArray()[0] 
				+ " limit " 
				+ this.exprList.getExprArray()[1];
		System.out.println("catchildren_sql:"+sql);
		List list = MallCat.dao.find(sql);
		scope.setGlobal("catChildrenList", list);
	}	
	public boolean headEnd(){
		return true;
	}
}
 
2017-03-29 14:31
感谢波总和@Irin.Chan 的回复,可能我功力还不够,或者我的表达不够清晰,如果我直接前端直接#catChildren(x.cat_id , 3) 调用,后台真的会报错