All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.gitee.cliveyuan.tools.sql.SqlTools Maven / Gradle / Ivy

There is a newer version: 4.0.6
Show newest version
package com.gitee.cliveyuan.tools.sql;

import com.gitee.cliveyuan.tools.StringTools;

/**
 * @author Clive Yuan
 * @date 2020/06/16
 */
public class SqlTools {

    private SqlTools() {
    }

    /**
     * 仅支持字母、数字、下划线、空格、逗号(支持多个字段排序)
     */
    public static String SQL_PATTERN = "[a-zA-Z0-9_\\ \\,]+";

    /**
     * 检查字符,防止注入绕过
     */
    public static String escapeOrderBySql(String value) {
        if (StringTools.isNotEmpty(value) && !isValidFieldName(value)) {
            return StringTools.EMPTY;
        }
        return value;
    }

    /**
     * 验证字段语法是否符合规范
     */
    public static boolean isValidFieldName(String fieldName) {
        return fieldName.matches(SQL_PATTERN);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy