WANG 6 years ago
parent
commit
6661d131cd
1 changed files with 19 additions and 0 deletions
  1. 19 0
      src/main/java/cn/com/qmth/examcloud/commons/util/DBUtil.java

+ 19 - 0
src/main/java/cn/com/qmth/examcloud/commons/util/DBUtil.java

@@ -9,6 +9,8 @@ import java.util.concurrent.ConcurrentHashMap;
 
 import javax.sql.DataSource;
 
+import org.apache.commons.lang3.StringUtils;
+
 import com.mchange.v2.c3p0.ComboPooledDataSource;
 import com.mchange.v2.c3p0.DataSources;
 
@@ -199,4 +201,21 @@ public class DBUtil {
 		}
 	}
 
+	/**
+	 * 转换为数据库模糊查询匹配模式
+	 *
+	 * @author WANGWEI
+	 * @param column
+	 * @return
+	 */
+	public static String toSqlSearchPattern(String column) {
+		if (StringUtils.isBlank(column)) {
+			return "%";
+		} else {
+			column = column.trim().replaceAll("\\s", "%");
+			column = "%" + column + "%";
+			return column;
+		}
+	}
+
 }