b
zhouxiang
2022-04-25 72586eaf36f18a51fafbe8e53fc55c236eb8bde0
b
2个文件已修改
30 ■■■■ 已修改文件
src/main/java/com/hx/mybatis/aes/springbean/MySqlInterceptor.java 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/hx/mybatis/aes/springbean/SqlUtils.java 17 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/hx/mybatis/aes/springbean/MySqlInterceptor.java
@@ -72,10 +72,15 @@
            sql = SqlUtils.deleteSql(sql, VariableAesKey.aesKeysTable);
        }
        //通过反射修改sql语句
        Field field = boundSql.getClass().getDeclaredField("sql");
        field.setAccessible(true);
        field.set(boundSql, sql);
        if(!"err".equals(sql)){
            //通过反射修改sql语句
            Field field = boundSql.getClass().getDeclaredField("sql");
            field.setAccessible(true);
            field.set(boundSql, sql);
        }
        return invocation.proceed();
    }
src/main/java/com/hx/mybatis/aes/springbean/SqlUtils.java
@@ -15,6 +15,8 @@
import com.alibaba.druid.util.JdbcConstants;
import com.alibaba.druid.util.JdbcUtils;
import com.hx.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Collection;
@@ -26,6 +28,9 @@
 * @author CJH 2022-01-12
 */
public class SqlUtils {
    //log4j日志
    private static Logger logger = LoggerFactory.getLogger(SqlUtils.class.getName());
    /**查询加密数据处理,只对查询做处理,select返回不做处理
     * @param sql sql语句
@@ -39,14 +44,22 @@
        //获取格式化的slq语句
        sql = sqlStatement.toString();
        //解析select查询
        //SQLSelect sqlSelect = sqlStatement.getSelect()
        //获取sql查询块
        SQLSelectQueryBlock sqlSelectQuery;
        SQLSelectQueryBlock sqlSelectQuery = null;
        boolean b = true;
        try{
            sqlSelectQuery = (SQLSelectQueryBlock)sqlStatement.getSelect().getQuery() ;
        }catch (Exception e){
            return sql;
            b = false;
            logger.error("解析sql报错:",e.getMessage());
        }
        if(!b){
            return "err";
        }
        StringBuffer out = new StringBuffer() ;