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

只谈情不闲聊 提交于 2019-12-04 12:08:07
  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

You should rewrite your generatorConfig.xml like this:

<table tableName="yourTableName" domainObjectName="JavaBeanName"
   enableCountByExample="false" 
   enableUpdateByExample="false"
   enableDeleteByExample="false" 
   enableSelectByExample="false"
   selectByExampleQueryId="false" 
   enableDeleteByPrimaryKey="false"
   enableInsert="false" 
   enableUpdateByPrimaryKey="false">
</table>

If you use MySQL, The crucial point is this:
{property name="nullCatalogMeansCurrent" value="true"}
reference: http://www.mybatis.org/generator/usage/intro.html


    <jdbcConnection
            driverClass="${driverClassName}"
            connectionURL="${url}"
            userId="${username}"
            password="${password}">
        <property name="nullCatalogMeansCurrent" value="true" />
    </jdbcConnection>

For example:


<generatorConfiguration>
<properties resource="mybatis-generator/generator.properties"></properties>
<classPathEntry location="${driverLocation}"/>
<context id="default" targetRuntime="MyBatis3">
    <commentGenerator>
        <property name="suppressDate" value="true"/>
        <property name="suppressAllComments" value="true"/>
    </commentGenerator>

    <jdbcConnection
            driverClass="${driverClassName}"
            connectionURL="${url}"
            userId="${username}"
            password="${password}">
       **<property name="nullCatalogMeansCurrent" value="true" />**
    </jdbcConnection>

    <javaTypeResolver>
        <property name="forceBigDecimals" value="false"/>
    </javaTypeResolver>

    <javaModelGenerator targetPackage="com.entity" targetProject="src/main/java">

        <property name="enableSubPackages" value="true"/>
    </javaModelGenerator>


    <sqlMapGenerator targetPackage="com.daoMappers" targetProject="src/main/resources">
        <property name="enableSubPackages" value="true"/>
    </sqlMapGenerator>


    <javaClientGenerator targetPackage="com.dao" targetProject="src/main/java" type="XMLMAPPER">
        <property name="enableSubPackages" value="true"/>
    </javaClientGenerator>


    <table tableName="student" domainObjectName="Student"
           enableCountByExample="false" 
           enableUpdateByExample="false"
           enableDeleteByExample="false" 
           enableSelectByExample="false"
           selectByExampleQueryId="false" 
           enableDeleteByPrimaryKey="false"
           enableInsert="false" 
           enableUpdateByPrimaryKey="false">
    </table>
</context>

Notes those should set by yourself


<properties resource="mybatis-generator/generator.properties"></properties>
<classPathEntry location="${driverLocation}"/>

The file of generator.properties coding like this:


driverClassName=com.mysql.cj.jdbc.Driver

driverLocation=/Users/mac/.m2/repository/mysql/mysql-connector-java/6.0.6/mysql-connector-java-6.0.6.jar

url=jdbc:mysql://localhost:3306/student?useSSL=false&useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&autoReconnect=true
username=xxx
password=xxx
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!