linzhijie
2021-03-11 84fea994d2db7dc313ad1774f34eb12a45f8d6e7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
package com.ots.common.utils.sql;
import com.ots.common.utils.StringUtils;
 
public class SqlUtil {
    
    public static String SQL_PATTERN = "[a-zA-Z0-9_\\ \\,]+";
    
    public static String escapeOrderBySql(String value) {
        if (StringUtils.isNotEmpty(value) && !isValidOrderBySql(value)) {
            return StringUtils.EMPTY;
        }
        return value;
    }
    
    public static boolean isValidOrderBySql(String value) {
        return value.matches(SQL_PATTERN);
    }
}