<!--mybatis逆向生成工具的核心jar--> <plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> <version>1.3.5</version> </plugin>
注意只能用這個generatorConfig名字,若是是其它的名字識別不了java
<?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> <!--指定驅動的位置--> <classPathEntry location="D:/Maven/repo/m2/mysql/mysql-connector-java/5.1.27/mysql-connector-java-5.1.27.jar"/> <!--生成對象環境 targetRuntime= MyBatis3:默認的值,還有一種是MyBatis3Simple--> <context id="mybatis" targetRuntime="MyBatis3Simple"> <commentGenerator> <property name="suppressDate" value="false"/> <property name="suppressAllComments" value="true"/> </commentGenerator> <!--數據庫相關設置--> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/spring" userId="root" password="123"/> <!--實體放置目錄--> <javaModelGenerator targetPackage="cn.yanxi.model" targetProject="src/main/java"> <property name="enableSubPackages" value="true"/> <property name="trimStrings" value="true"/> </javaModelGenerator> <!--mybatis映射xml文件放置位置--> <sqlMapGenerator targetPackage="config.mapping" targetProject="src/main/resources"> <property name="enableSubPackages" value="true"/> </sqlMapGenerator> <!--mapper接口--> <javaClientGenerator targetPackage="cn.yanxi.dao" targetProject="src/main/java" type="XMLMAPPER"> <property name="enableSubPackages" value="true"/> </javaClientGenerator> <!--能夠配置多個表--> <table tableName="user" domainObjectName="User" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> </table> </context> </generatorConfiguration>
javaClientGenerator的type值mysql
注意,若是context是MyBatis3Simple:只支持ANNOTATEDMAPPER和XMLMAPPER
參照於網上的一些博文spring
###運行 測試 sql
[INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building ssmTest Maven Webapp 1.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- mybatis-generator-maven-plugin:1.3.5:generate (default-cli) @ ssmTest --- [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 0.741 s [INFO] Finished at: 2016-11-19T13:45:23+08:00 [INFO] Final Memory: 10M/155M [INFO] ------------------------------------------------------------------------ Process finished with exit code 0