package com.hx.mybatis.aes.springbean;
|
|
import com.alibaba.druid.sql.ast.statement.SQLExprTableSource;
|
import com.alibaba.druid.sql.visitor.SQLASTVisitorAdapter;
|
|
import java.util.HashMap;
|
import java.util.Map;
|
|
/**
|
* ExportTableAliasVisitor
|
* @author Mwg
|
* @date 2020/09/08 23:47
|
*/
|
public class ExportTableAliasVisitor extends SQLASTVisitorAdapter {
|
|
private Map<String,String> tableMap = new HashMap<>();
|
|
public Map<String, String> getTableMap() {
|
return tableMap;
|
}
|
|
public void setTableMap(Map<String, String> tableMap) {
|
this.tableMap = tableMap;
|
}
|
|
@Override
|
public boolean visit(SQLExprTableSource x) {
|
|
//别名,如果有别名,别名保持不变
|
//System.out.println("alias:"+x.getAlias());//别名
|
//System.out.println("expr:"+x.getExpr());//表名
|
tableMap.put(x.getExpr().toString(),x.getAlias());
|
|
|
//String s = StringUtils.isEmpty(x.getAlias()) ? x.getExpr().toString() : x.getAlias();
|
|
// 修改表名,不包含点才加 select id from c left join d on c.id = d.id 中的c 和 d
|
|
/*if(!x.getExpr().toString().contains(".")) {
|
|
x.setExpr("`" + dbName.get() + "`." + x.getExpr());
|
|
}*/
|
//x.setExpr("mymymytable");//修改表名
|
//x.setAlias("aa");//修改别名
|
//x.setAlias(s);
|
return true;
|
|
}
|
|
|
|
}
|