新增[自定义查询sql]
This commit is contained in:
@@ -12,6 +12,7 @@ import java.util.List;
|
||||
public class Filter {
|
||||
private String col;
|
||||
private String value;
|
||||
private String[] values;
|
||||
private String type;
|
||||
//----------------------
|
||||
|
||||
|
||||
@@ -15,7 +15,10 @@ public enum FilterType {
|
||||
GREATERTHANOREQUALTO(">=", ">="),
|
||||
LESSTHAN("<", "小于"),
|
||||
LIKE("LIKE", "LIKE"),
|
||||
IN("IN", "包含");
|
||||
IN("IN", "包含"),
|
||||
RANGE("RANGE", "区间"),
|
||||
SQL("SQL", "SQL") //直接使用sql查询
|
||||
;
|
||||
|
||||
private String expre;
|
||||
private String remark;
|
||||
@@ -35,7 +38,7 @@ public enum FilterType {
|
||||
return "";
|
||||
}
|
||||
|
||||
String _sql;
|
||||
String _sql = "";
|
||||
switch (filterType) {
|
||||
case IN:
|
||||
_sql = String.format(" AND %s IN (%s)", filter.getCol(), filter.getValue());
|
||||
@@ -43,9 +46,20 @@ public enum FilterType {
|
||||
case LIKE:
|
||||
_sql = String.format(" AND %s LIKE '%s'", filter.getCol(), "%" + filter.getValue() + "%");
|
||||
break;
|
||||
case RANGE:
|
||||
if (filter.getValues() != null) {
|
||||
if (filter.getValues().length == 1) {
|
||||
_sql = String.format(" AND %s>='%s'", filter.getCol(), filter.getValues()[0]);
|
||||
} else if (filter.getValues().length == 2) {
|
||||
_sql = String.format(" AND (%s>='%s' and %s<'%s')", filter.getCol(), filter.getValues()[0], filter.getCol(), filter.getValues()[1]);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SQL:
|
||||
_sql = String.format(" AND (%s)", filter.getValue());
|
||||
break;
|
||||
default:
|
||||
_sql = String.format(" AND %s %s '%s'", filter.getCol(), filterType.expre, filter.getValue());
|
||||
break;
|
||||
}
|
||||
|
||||
return _sql;
|
||||
|
||||
Reference in New Issue
Block a user