1. 程式人生 > >Mybatis 自動生成mapper檔案

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>