-
Notifications
You must be signed in to change notification settings - Fork 8.6k
TableMapping_cn
高铁 edited this page Sep 24, 2016
·
2 revisions
在druid-1.2.17版本中,新增加一个功能TableMapping,用于修改SQL中的表名。
package com.alibaba.druid.sql;
public class SQLUtils {
public static String refactor(String sql, String dbType, Map<String, String> tableMapping);
}
- sql 需要修改的SQL
- dbType 数据库类型,在JdbcConstants中定义有各种数据库类型的常量,比如mysql/oracle/db2/sqlserver/odps等
- tableMapping 需要映射的表名
- 返回值 映射修改后的SQL
import com.alibaba.druid.sql.SQLUtils;
Map<String, String> mapping = Collections.singletonMap("user", "user_01");
String sql = "select * from user";
String result = SQLUtils.refactor(sql, JdbcConstants.MYSQL, mapping);
assertEquals("SELECT *\n" +
"FROM user_01", result);