package com.xf.config; import com.alibaba.druid.sql.ast.statement.SQLExprTableSource; import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitorAdapter; public class MySqlExportTableAliasVisitor extends MySqlASTVisitorAdapter { @Override public boolean visit(SQLExprTableSource x) { x.setExpr("saas_base."+x.getTableName()); return true; } }
拦截sql后替换
protected String changeTable(String sql) { DbType dbType = JdbcConstants.MYSQL; List<SQLStatement> stmtList = SQLUtils.parseStatements(sql, dbType); for (SQLStatement sqlStatement : stmtList) { MySqlASTVisitorAdapter visitor = new MySqlExportTableAliasVisitor(); sqlStatement.accept(visitor); } return SQLUtils.toSQLString(stmtList, JdbcConstants.MYSQL); }
标签:visitor,MySqlASTVisitorAdapter,表名,stmtList,sql,拦截,com From: https://www.cnblogs.com/wujf/p/17145107.html