Search code examples
mybatismybatis-generator

Mybatis Generator: How to generate all tables for a specified schema


Mysql database totally has 4 schemas, and I just want to generate a specified schema named 'booking'. But it always generate all tables for all schemas. So I need your help. Below is my generatorConfig.xml.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
        PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
        "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">

<generatorConfiguration>
    <context id="MySqlContext" targetRuntime="MyBatis3Simple" defaultModelType="flat">
        <jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
                        connectionURL="jdbc:mysql://localhost:3306/booking?useSSL=false"
                        userId="root"
                        password="123456">
        </jdbcConnection>

        <javaModelGenerator targetPackage="com.clycle.booking.entity" targetProject="C:\Users\a243903\projects\booking\webapi\src\main\java">
            <property name="enableSubPackages" value="true" />
            <property name="trimStrings" value="true" />
        </javaModelGenerator>

        <sqlMapGenerator targetPackage="entity-mapper"  targetProject="C:\Users\a243903\projects\booking\webapi\src\main\resources">
            <property name="enableSubPackages" value="true" />
        </sqlMapGenerator>

        <javaClientGenerator type="XMLMAPPER" targetPackage="dao"  targetProject="C:\Users\a243903\projects\booking\webapi\src\main\java">
            <property name="enableSubPackages" value="true" />
        </javaClientGenerator>

        <table schema="booking" tableName="%">
        </table>

    </context>
</generatorConfiguration>

Solution

    1. Make your table configuration look like this: <table tableName="%"/>
    2. Add <property name="nullCatalogMeansCurrent" value=true" /> under the <jdbcConnection>

    See this reference page for more information: http://www.mybatis.org/generator/usage/mysql.html