增加pom.xml文件
<plugins>
<!-- mybatis-generator自動生成代碼插件 -->
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<!--<configurationFile>
<!– 該路徑就是我們創建generatorConfig.xml文件的全路徑,千萬別配錯了 –>
src/resources/generator/generatorConfig.xml
</configurationFile>-->
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
</plugin>
</plugins>
jdbc.properties配置
文件中增加jar地址,不然後說一直無法解析/mysql-connector-java-5.1.29.jar路徑問題
driverClasss=com.mysql.jdbc.Driver
jdbcUrl=jdbc:mysql://localhost:3306/boke
username=hap_dev
password=hap_dev
#定義初始連接數
initialSize=0
#定義最大連接數
maxActive=20
#定義最大空閒
maxIdle=20
#定義最小空閒
minIdle=1
#定義最長等待時間
maxWait=60000
driverLocation=F:/m2/repository/mysql/mysql-connector-java/5.1.29/mysql-connector-java-5.1.29.jar
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>
<!--導入屬性配置-->
<properties resource="jdbc.properties"></properties>
<!-- mysql-connector文件路徑 -->
<classPathEntry location="${driverLocation}"/>
<!-- context 是逆向工程的主要配置信息 -->
<!-- id:起個名字 -->
<!-- targetRuntime:設置生成的文件適用於那個 mybatis 版本 -->
<context id="DB2Tables" targetRuntime="MyBatis3">
<commentGenerator>
<property name="suppressDate" value="true"/>
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<!-- 鏈接配置 輸入你的數據庫名及密碼 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/boke"
userId="hap_dev" password="hap_dev">
</jdbcConnection>
<javaTypeResolver>
<property name="forceBigDecimals" value="false"/>
</javaTypeResolver>
<!-- 生成實體類的路徑,yuan.boke.www.entity 這個路徑可以自動生成,但是必須有src這個路徑-->
<javaModelGenerator targetPackage="java.yuan.boke.www.entity"
targetProject="src">
<property name="enableSubPackages" value="true"/>
<property name="trimStrings" value="true"/>
</javaModelGenerator>
<!-- 生成映射的路徑,這個路徑可以自動生成,但是必須有src這個路徑-->
<sqlMapGenerator targetPackage="java.yuan.boke.www.mapping" targetProject="src">
<property name="enableSubPackages" value="true"/>
</sqlMapGenerator>
<!-- 生成接口的路徑,這個路徑可以自動生成,但是必須有src這個路徑-->
<javaClientGenerator type="XMLMAPPER" targetPackage="java.yuan.boke.www.dao"
targetProject="src">
<property name="enableSubPackages" value="true"/>
</javaClientGenerator>
<!-- 表名、實體類名稱 -->
<table tableName="user" domainObjectName="User" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
<table tableName="user_info" domainObjectName="UserInfo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
<table tableName="resource" domainObjectName="Resource" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
<table tableName="user_content" domainObjectName="UserContent" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
<table tableName="comment" domainObjectName="Comment" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
<table tableName="login_log" domainObjectName="LoginLog" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
<table tableName="role" domainObjectName="Role" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
<table tableName="role_resource" domainObjectName="RoleResource" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
<table tableName="role_user" domainObjectName="RoleUser" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
<table tableName="upvote" domainObjectName="Upvote" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
</context>
</generatorConfiguration>
這樣就可以了。