我用这个代码测了一下,and表达式可以支持,完整代码见附件。
复制内容到剪贴板
代码:
public static void main(String[] args) {
try {
// 准备数据集
Object[][] data = {
{ "崔永远", 18 },
{ "王小鸭", 16 }
};
jatools.dataset.Column[] columns = new jatools.dataset.Column[2];
columns[0] = new jatools.dataset.Column("姓名", String.class);
columns[1] = new jatools.dataset.Column("年龄", Integer.class);
RowMeta rowMeta = new RowMeta(columns);
Statement stat = new CCJSqlParserManager().parse(new StringReader(
"select * from a where 姓名='崔永远' and 年龄=18"));
Select select = (Select) stat;
Expression where = ((PlainSelect) select.getSelectBody()).getWhere();
Map<String, Integer> _columns = new HashMap<String, Integer>();
for (int i = 0; i < rowMeta.getColumnCount(); i++) {
_columns.put(rowMeta.getColumnName(i).toUpperCase(), i);
}
WhereExpressionVisitor visitor = new WhereExpressionVisitor(_columns, where);
for (int i = 0; i < data.length; i++) {
Object result = visitor.eval(data[i]);
if (result instanceof Boolean && ((Boolean) result).booleanValue()) {
System.out.print("通过=====>");
} else {
System.out.print("不通过=====>");
}
System.out.println(StringUtils.join(data[i], ","));
}
} catch (JSQLParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}