Mybatis 自动生成mapper文件

 

在pom.xml下的<build>内加入:

 <build>

    <plugins>
      <plugin>
        <groupId>org.mybatis.generator</groupId>
        <artifactId>mybatis-generator-maven-plugin</artifactId>
        <version>1.3.7</version>

        <configuration>
          <configurationFile>${basedir}/src/main/resources/generatorConfig.xml</configurationFile>
          <overwrite>true</overwrite>
        </configuration>

        <dependencies>
          <dependency>
            <groupId>org.mariadb.jdbc</groupId>
            <artifactId>mariadb-java-client</artifactId>
            <version>2.3.0</version>
          </dependency>
        </dependencies>
      </plugin>
    </plugins>

  </build>

 

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>
    <!--jdbc 驱动包,等-->
    <!--<classPathEntry location="/Program Files/IBM/SQLLIB/java/db2java.zip" />-->

    <context id="sss" targetRuntime="MyBatis3Simple">

        <commentGenerator>
            <property name="suppressAllComments" value="true" />
        </commentGenerator>

        <jdbcConnection driverClass="org.mariadb.jdbc.Driver"
                        connectionURL="jdbc:mariadb://localhost/employeedb"
                        userId="root"
                        password="666666">
        </jdbcConnection>

        <javaModelGenerator targetPackage="com.nf147.manage.entity" targetProject="src\main\java">
            <property name="trimStrings" value="true" />
        </javaModelGenerator>

        <sqlMapGenerator targetPackage="mappers"  targetProject="src\main\resources">
        </sqlMapGenerator>

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

        <table tableName="staff">   如果多个表把tableName="%" 改为百分号
 <property name="useActualColumnNames" value="true"/> </table> </context> </generatorConfiguration>

 

posted @ 2018-12-05 09:40  随★风  阅读(3953)  评论(0编辑  收藏  举报