generator配置多数据源配置

窦哲彦
2023-12-01
分别创建两个文件,将数据源分开写
<?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>
    <properties resource="ceshi.properties"/>

    <context id="Mysql" targetRuntime="MyBatis3Simple" defaultModelType="flat">
        <property name="beginningDelimiter" value="`"/>
        <property name="endingDelimiter" value="`"/>

        <plugin type="tk.mybatis.mapper.generator.MapperPlugin">
            <property name="mappers" value="tk.mybatis.mapper.common.Mapper"/>
        </plugin>

        <jdbcConnection driverClass="${spring.datasource.master.driverClassName}"
                        connectionURL="${spring.datasource.master.url}"
                        userId="${spring.datasource.master.name}"
                        password="${spring.datasource.master.pwd}">
        </jdbcConnection>

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

        <sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources"/>

        <javaClientGenerator targetPackage="com.hmq.dao" targetProject="src/main/java"
                             type="XMLMAPPER"/>

      
    </context>
</generatorConfiguration>

 

pom.xml中配置

<plugin>
    <groupId>org.mybatis.generator</groupId>
    <artifactId>mybatis-generator-maven-plugin</artifactId>
    <version>1.3.2</version>
    <configuration>
        <configurationFile>${dir}/src/main/resources/generator/a.xml</configurationFile>
        <configurationFile>${dir}/src/main/resources/generator/b.xml</configurationFile>
        <overwrite>true</overwrite>
        <verbose>true</verbose>
    </configuration>
    <dependencies>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.11</version>
            <!--<scope>runtime</scope>-->
        </dependency>
        <dependency>
            <groupId>tk.mybatis</groupId>
            <artifactId>mapper</artifactId>
            <version>3.4.0</version>
        </dependency>

    </dependencies>
</plugin>
 类似资料: