2021SC@SDUSC
public static String isNull(String s) {
return isNull(s, true);
}
/**
* @param s
* @param isNull
* @return s + {@link #isNull(boolean)}
*/
public static String isNull(String s, boolean isNull) {
return s + isNull(isNull);
}
/**
* isEmpty = true
* @param s
* @return {@link #isEmpty(String, boolean)}
*/
public static String isEmpty(String s) {
return isEmpty(s, true);
}
/**
* trim = false
* @param s
* @param isEmpty
* @return {@link #isEmpty(String, boolean, boolean)}
*/
public static String isEmpty(String s, boolean isEmpty) {
return isEmpty(s, isEmpty, false);
}
public static String isEmpty(String s, boolean isEmpty, boolean trim) {
return isEmpty(s, isEmpty, trim, true);
}
判断字符串是否为空
public static String isEmpty(String s, boolean isEmpty, boolean trim, boolean nullable) {
if (trim) {
s = trim(s);
}
return (nullable ? isNull(s, true) + OR : "") + lengthCompare(s, (isEmpty ? "<=" : ">") + "0");
}
先将字符串去掉符号
然后用?:进行判断赋值
判断是否为空
public static String column(String column) {
column = StringUtil.getTrimedString(column);
return column.isEmpty() ? "*" : column;
}
返回列名组
public static String function(String fun, String column) {
if (StringUtil.isEmpty(column, true) || column.contains(","))
column = null;
return " " + fun + "(" + column(column) + ") ";
}
解决 count(id,name) 这种多个字段导致的SQL异常
public static String search(String s) {
return search(s, SEARCH_TYPE_CONTAIN_FULL);
}
获取搜索值
public static String search(String s, int type, boolean ignoreCase) {
if (s == null) {
return null;
}
switch (type) {
case SEARCH_TYPE_CONTAIN_SINGLE:
return "_" + s + "_";
case SEARCH_TYPE_CONTAIN_ORDER:
char[] cs = s.toCharArray();
if (cs == null) {
return null;
}
String value = "%";
for (int i = 0; i < cs.length; i++) {
value += cs[i] + "%";
}
return value;
case SEARCH_TYPE_START:
return s + "%";
case SEARCH_TYPE_END:
return "%" + s;
case SEARCH_TYPE_START_SINGLE:
return s + "_";
case SEARCH_TYPE_END_SINGLE:
return "_" + s;
case SEARCH_TYPE_CONTAIN_ANY:
case SEARCH_TYPE_PART_MATCH:
cs = s.toCharArray();
if (cs == null) {
return null;
}
value = "";
for (int i = 0; i < cs.length; i++) {
value += search("" + cs[i], SEARCH_TYPE_CONTAIN_FULL, ignoreCase);
}
return value;
default://SEARCH_TYPE_CONTAIN_FULL
return "%" + s + "%";
}
}
这一段代码是分析字符串的类型
如果含有命令的话,就把它分为字符,用%分割开来,再return