/*
 * Copyright (c) 2011-2020, baomidou (jobob@qq.com).
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * <p>
 * https://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.baomidou.mybatisplus.extension.parsers;

import org.apache.ibatis.reflection.MetaObject;

/**
 * 动态表名处理器
 *
 * @author jobob
 * @since 2019-04-23
 */
public interface ITableNameHandler {

    /**
     * 表名 SQL 处理
     *
     * @param metaObject 元对象
     * @param sql        当前执行 SQL
     * @param tableName  表名
     * @return
     */
    default String process(MetaObject metaObject, String sql, String tableName) {
        String dynamicTableName = dynamicTableName(metaObject, sql, tableName);
        if (null != dynamicTableName && !dynamicTableName.equalsIgnoreCase(tableName)) {
            return sql.replaceAll(tableName, dynamicTableName);
        }
        return sql;
    }

    /**
     * 生成动态表名，无改变返回 NULL
     *
     * @param metaObject 元对象
     * @param sql        当前执行 SQL
     * @param tableName  表名
     * @return String
     */
    String dynamicTableName(MetaObject metaObject, String sql, String tableName);
}

@@ -1213,24 +1213,149 @@
 bleName)) %7B%0A
+            // %E7%9B%B4%E6%8E%A5%E6%9B%BF%E6%8D%A2%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%AF%B9%E4%BA%8E SQL %E6%93%8D%E4%BD%9C%E6%98%AF%E4%B8%8D%E9%82%A3%E4%B9%88%E5%A5%BD%E5%81%9A%EF%BC%8C%E8%BF%99%E9%87%8C%E4%BF%AE%E5%A4%8D%E5%8F%AA%E8%83%BD%E5%B0%BD%E5%8F%AF%E8%83%BD%E7%9A%84%E4%BF%9D%E8%AF%81%E5%A4%84%E7%90%86%E6%B2%A1%E9%97%AE%E9%A2%98%0A            String regex = %22(?%3C=%5C%5Cs)%5C%5CQ%22 + tableName + %22%5C%5CE(?=%5C%5Cs)%22;%0A
             
@@ -1376,25 +1376,21 @@
 laceAll(
-tableName
+regex
 , dynami

修复动态表名 BUG，最大努力替换表名