剥离 sql 单独提出至 SqlUtils

This commit is contained in:
= 2018-01-09 17:58:53 +08:00
parent b69bf56807
commit 3a377b1c99
2 changed files with 16 additions and 13 deletions

View File

@ -105,7 +105,7 @@ public abstract class Wrapper<T> implements Serializable {
}
public String getSqlSelect() {
return StringUtils.isEmpty(sqlSelect) ? null : stripSqlInjection(sqlSelect);
return StringUtils.isEmpty(sqlSelect) ? null : SqlUtils.stripSqlInjection(sqlSelect);
}
public Wrapper<T> setSqlSelect(String sqlSelect) {
@ -1435,18 +1435,6 @@ public abstract class Wrapper<T> implements Serializable {
return need ? where(sqlWhere, params) : this;
}
/**
* <p>
* SQL注入内容剥离
* </p>
*
* @param value 待处理内容
* @return this
*/
protected String stripSqlInjection(String value) {
return value.replaceAll("('.+--)|(--)|(\\|)|(%7C)", "");
}
/**
* <p>
* 格式化SQL

View File

@ -162,4 +162,19 @@ public class SqlUtils {
return builder.toString();
}
/**
* <p>
* SQL注入内容剥离
* </p>
*
* @param sql 待处理 SQL 内容
* @return this
*/
public static String stripSqlInjection(String sql) {
if (null == sql) {
throw new MybatisPlusException("strip sql is null.");
}
return sql.replaceAll("('.+--)|(--)|(\\|)|(%7C)", "");
}
}