Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
*
* @author [email protected]
* @date 2019年3月5日 下午11:30:02
*/
public class BuildWhere {
public static final String LESS = "<";
public static final String LESS_OR_EQUAL = "<=";
public static final String EQUAL = "=";
public static final String NOT_EQUAL = "!=";
public static final String GREATER = ">";
public static final String GREATER_OR_EQUAL = ">=";
public static final String EXISTS = "exists";
public static final String LIKE = "like";
public static final String IN = "in";
public static final String NOT_IN = "nin";
public static final String OR = "or";
public static final String AND = "and";
public static final Map elMap = new HashMap();
static {
elMap.put(LESS, " < ");
elMap.put(LESS_OR_EQUAL, " <= ");
elMap.put(EQUAL, " = ");
elMap.put(LIKE, " like ");
elMap.put(NOT_EQUAL, " != ");
elMap.put(GREATER, " > ");
elMap.put(GREATER_OR_EQUAL, " >= ");
elMap.put(IN, " in ");
elMap.put(NOT_IN, " not in ");
elMap.put(EXISTS, " is null ");
}
public static SqlRes getWheres(SqlFilter sqlFilter) {
SqlRes sqlRes = new SqlRes();
StringBuilder currSql = new StringBuilder();
int i = 0;
for (Filter filter : sqlFilter.getFilters()) {
if (i > 0) {
if (sqlFilter.isAnd()) {
currSql.append(" and ");
} else {
currSql.append(" or ");
}
}
oneFilter(filter, currSql, sqlRes.getWhereVals());
i++;
}
if (currSql.length() > 2) {
if (sqlFilter.isWherePre()) {// 有where前缀
if (sqlFilter.isAnd()) {
sqlRes.setWhereSql(" and (" + currSql + ")");
} else {
sqlRes.setWhereSql(" or (" + currSql + ")");
}
} else {
sqlRes.setWhereSql(" where " + currSql);
}
}
return sqlRes;
}
private static boolean hasEl(Filter filter) {
if (StringUtils.isBlank(filter.getCol()) || StringUtils.isBlank(filter.getOp()) || filter.getVal() == null) {
return false;
}
return true;
}
/**
*