public void preHandle(BoundSql boundSql, RequestEntity requestEntity) { System.out.println("要执行的SQL:" + boundSql.getSql()); System.out.println("要执行的SQL参数:" + Arrays.toString(boundSql.getParameters())); // 用druid解析出表名 List<String> tableNameList = new ArrayList<String>(); String dbType = JdbcConstants.MYSQL; List<SQLStatement> stmtList = SQLUtils.parseStatements(boundSql.getSql(), dbType); for (SQLStatement sqlStatement : stmtList) { MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor(); sqlStatement.accept(visitor); Map<TableStat.Name, TableStat> tables = visitor.getTables(); System.out.println("druid解析sql的结果集:"); System.out.println(tables); Set<TableStat.Name> tableNameSet = tables.keySet(); for (TableStat.Name name : tableNameSet) { String tableName = name.getName(); if (StrUtil.isNotBlank(tableName)) { tableNameList.add(tableName); } } } }
标签:visitor,saas,System,druid,boundSql,表名,println,out From: https://www.cnblogs.com/wujf/p/17095001.html