fwq
2022-05-09 8fcea52f023500d5ada8afc533989592493e79ce
src/main/java/com/hx/mybatis/aes/springbean/MySqlInterceptor.java
@@ -62,30 +62,23 @@
        //这里可以进行sql修改
        //获取到原始sql语句
        String sql = boundSql.getSql();
        String sql2 = null;
        //新增
        if(sqlCommandType == SqlCommandType.INSERT){
            sql2 = SqlUtils.insertSql(sql, VariableAesKey.aesKeysTable);
            sql = SqlUtils.insertSql(sql, VariableAesKey.aesKeysTable);
        }else if(sqlCommandType == SqlCommandType.UPDATE){
            sql2 = SqlUtils.updateSql(sql, VariableAesKey.aesKeysTable);
            sql = SqlUtils.updateSql(sql, VariableAesKey.aesKeysTable);
        }else if(sqlCommandType == SqlCommandType.SELECT){
            if(VariableAesKey.isRun == 1){
                sql2 = SqlUtils.selectSql(sql, VariableAesKey.aesKeysTable);
            }else{
                sql2  = sql;
                sql = SqlUtils.selectSql(sql, VariableAesKey.aesKeysTable);
            }
        }else if(sqlCommandType == SqlCommandType.DELETE){
            sql2 = SqlUtils.deleteSql(sql, VariableAesKey.aesKeysTable);
        }else{
            sql2  = sql;
            sql = SqlUtils.deleteSql(sql, VariableAesKey.aesKeysTable);
        }
        if(!"err".equals(sql2)){
            //通过反射修改sql语句
            Field field = boundSql.getClass().getDeclaredField("sql");
            field.setAccessible(true);
            field.set(boundSql, sql2);
        }
        //通过反射修改sql语句
        Field field = boundSql.getClass().getDeclaredField("sql");
        field.setAccessible(true);
        field.set(boundSql, sql);
        return invocation.proceed();