zhouxiang
2022-04-25 8ab2ad5580212b91df848e4c127f2a682485fde3
修改common
2个文件已修改
26 ■■■■■ 已修改文件
src/main/java/com/hx/mybatis/aes/springbean/MySqlInterceptor.java 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/hx/mybatis/aes/springbean/SqlUtils.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/hx/mybatis/aes/springbean/MySqlInterceptor.java
@@ -10,6 +10,8 @@
import org.apache.ibatis.reflection.MetaObject;
import org.apache.ibatis.reflection.SystemMetaObject;
import org.apache.ibatis.session.Configuration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.lang.reflect.Field;
@@ -25,6 +27,8 @@
        })
})
public class MySqlInterceptor implements Interceptor {
    private static Logger logger = LoggerFactory.getLogger(MySqlInterceptor.class.getName());
    @Override
    public Object intercept(Invocation invocation) throws Throwable {
@@ -58,27 +62,29 @@
        //这里可以进行sql修改
        //获取到原始sql语句
        String sql = boundSql.getSql();
        String sql2 = null;
        //新增
        if(sqlCommandType == SqlCommandType.INSERT){
            sql = SqlUtils.insertSql(sql, VariableAesKey.aesKeysTable);
            sql2 = SqlUtils.insertSql(sql, VariableAesKey.aesKeysTable);
        }else if(sqlCommandType == SqlCommandType.UPDATE){
            sql = SqlUtils.updateSql(sql, VariableAesKey.aesKeysTable);
            sql2 = SqlUtils.updateSql(sql, VariableAesKey.aesKeysTable);
        }else if(sqlCommandType == SqlCommandType.SELECT){
            if(VariableAesKey.isRun == 1){
                sql = SqlUtils.selectSql(sql, VariableAesKey.aesKeysTable);
                sql2 = SqlUtils.selectSql(sql, VariableAesKey.aesKeysTable);
            }else{
                sql2  = sql;
            }
        }else if(sqlCommandType == SqlCommandType.DELETE){
            sql = SqlUtils.deleteSql(sql, VariableAesKey.aesKeysTable);
            sql2 = SqlUtils.deleteSql(sql, VariableAesKey.aesKeysTable);
        }else{
            sql2  = sql;
        }
        if(!"err".equals(sql)){
        if(!"err".equals(sql2)){
            //通过反射修改sql语句
            Field field = boundSql.getClass().getDeclaredField("sql");
            field.setAccessible(true);
            field.set(boundSql, sql);
            field.set(boundSql, sql2);
        }
        return invocation.proceed();
src/main/java/com/hx/mybatis/aes/springbean/SqlUtils.java
@@ -55,7 +55,7 @@
            sqlSelectQuery = (SQLSelectQueryBlock)sqlStatement.getSelect().getQuery() ;
        }catch (Exception e){
            b = false;
            logger.error("解析sql报错:",e.getMessage());
            logger.error("解析sql报错:"+e.getMessage());
        }
        if(!b){