package top.lvzhiqiang.util; /** * 字符串处理工具类 * * @author shiyong * 2021/10/25 10:48 */ public class StringUtils extends org.apache.commons.lang3.StringUtils { // 百分号,SQL参数中的任意长度通配符 private static final String PERCENT = "%"; // 下划线,SQL参数中的单个字符通配符 private static final String UNDERLINE = "_"; /** * 判断字符串是否不为空 * * @param str 字符串 * @return boolean * @author shiyong * 2019/10/16 16:15 */ public static boolean isNotEmpty(String str){ return null != str && !"".equals(str.trim()); } /** * 判断字符串是否为空 * * @param str 字符串 * @return boolean * @author shiyong * 2019/10/16 16:16 */ public static boolean isEmpty(String str) { return !isNotEmpty(str); } /** * 转义SQL参数中的通配符 * * @param raw 原字符串 * @return escaped sql parameter * @author ziyan.li * @since 15:00 2021/10/27 */ public static String escapeSqlParam(String raw) { if (raw == null) { return null; } // 转义通配符 String processed = raw.replace(PERCENT, "\\" + PERCENT) .replace(UNDERLINE, "\\" + UNDERLINE); // 转义后去除前后空格 return strip(processed); } public static String escapeJavParam(String raw) { if (raw == null) { return null; } // 转义通配符 String processed = raw.replace("/", "") .replace("?", "?") .replace("%", "%") .replace("#",""); // 转义后去除前后空格 return strip(processed); } }