mybatis-plus生成多表join的sql语句

1.demo

package com.hecr;

import cn.hutool.core.util.StrUtil;

public class SqlUtil {
    private static final String SQL_TEMPLATE = "";

    public static String format(String defaultSelctColumn, String defaultSearchSql) {
        return StrUtil.format(SQL_TEMPLATE, defaultSelctColumn, defaultSearchSql);
    }

    public static void main(String[] args) {
        String format = SqlUtil.format("m.member_id", "FROM t_table0 AS m\n" +
                "JOIN t_table1 AS mtr ON mtr.member_id = m.member_id\n" +
                "JOIN t_table2 AS mt ON mt.tag_id = mtr.tag_id");
        System.out.println(format);
    }

    public static String filterSql(String keyword) {
        if (StrUtil.isBlank(keyword)) {
            return keyword;
        }
        keyword = keyword.trim().replaceAll("\\s", "")
                .replace("\\", "\\\\")
                .replace("_", "\\_")
                .replace("\'", "\\'")
                .replace("%", "\\%")
                .replace("*", "\\*")
                .replace("\"", "\\\"");
        return keyword;
    }
}

2.生成的sql

<script>
SELECT
<choose>
<when test="ew.sqlSelect != null and ew.sqlSelect !=''">
${ew.sqlSelect}
</when>
<otherwise>
m.member_id
</otherwise>
</choose>
FROM t_table0 AS m
JOIN t_table1 AS mtr ON mtr.member_id = m.member_id
JOIN t_table2 AS mt ON mt.tag_id = mtr.tag_id
${ew.customSqlSegment}
</script>

你可能感兴趣的:(关系型数据库,mybatis,sql,mysql)