提交 | 用户 | age
|
c64e12
|
1 |
package com.hx.mybatis.aes.springbean; |
C |
2 |
|
|
3 |
import com.alibaba.druid.sql.ast.statement.SQLExprTableSource; |
|
4 |
import com.alibaba.druid.sql.visitor.SQLASTVisitorAdapter; |
|
5 |
|
|
6 |
import java.util.HashMap; |
|
7 |
import java.util.Map; |
|
8 |
|
|
9 |
/** |
|
10 |
* ExportTableAliasVisitor |
|
11 |
* @author Mwg |
|
12 |
* @date 2020/09/08 23:47 |
|
13 |
*/ |
|
14 |
public class ExportTableAliasVisitor extends SQLASTVisitorAdapter { |
|
15 |
|
|
16 |
private Map<String,String> tableMap = new HashMap<>(); |
|
17 |
|
|
18 |
public Map<String, String> getTableMap() { |
|
19 |
return tableMap; |
|
20 |
} |
|
21 |
|
|
22 |
public void setTableMap(Map<String, String> tableMap) { |
|
23 |
this.tableMap = tableMap; |
|
24 |
} |
|
25 |
|
|
26 |
@Override |
|
27 |
public boolean visit(SQLExprTableSource x) { |
|
28 |
|
|
29 |
//别名,如果有别名,别名保持不变 |
|
30 |
//System.out.println("alias:"+x.getAlias());//别名 |
|
31 |
//System.out.println("expr:"+x.getExpr());//表名 |
|
32 |
tableMap.put(x.getExpr().toString(),x.getAlias()); |
|
33 |
|
|
34 |
|
|
35 |
//String s = StringUtils.isEmpty(x.getAlias()) ? x.getExpr().toString() : x.getAlias(); |
|
36 |
|
|
37 |
// 修改表名,不包含点才加 select id from c left join d on c.id = d.id 中的c 和 d |
|
38 |
|
|
39 |
/*if(!x.getExpr().toString().contains(".")) { |
|
40 |
|
|
41 |
x.setExpr("`" + dbName.get() + "`." + x.getExpr()); |
|
42 |
|
|
43 |
}*/ |
|
44 |
//x.setExpr("mymymytable");//修改表名 |
|
45 |
//x.setAlias("aa");//修改别名 |
|
46 |
//x.setAlias(s); |
|
47 |
return true; |
|
48 |
|
|
49 |
} |
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
} |