<?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="C:\Users\Gost\Desktop\SpringMvc+Spring+MyBatis+Maven\generator\generator\mysql-connector-java-5.1.26-bin.jar" />
<context id="DB2Tables" targetRuntime="MyBatis3">
<commentGenerator>
<property name="suppressAllComments" value="true" />
</commentGenerator>
<!-- 數據庫連接URL、用戶名、密碼 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/sy" userId="root" password="123456">
</jdbcConnection>
<javaTypeResolver>
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!-- 生成模型的包名和位置 -->
<javaModelGenerator targetPackage="cn.lsu.model" targetProject="C:\Users\Gost\Desktop\SpringMvc+Spring+MyBatis+Maven\generator\generator\src">
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!-- 生成的映射文件包名和位置 -->
<sqlMapGenerator targetPackage="cn.lsu.mapping" targetProject="C:\Users\Gost\Desktop\SpringMvc+Spring+MyBatis+Maven\generator\generator\src">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>
<!-- 生成DAO的包名和位置 -->
<javaClientGenerator type="XMLMAPPER" targetPackage="cn.lsu.dao" targetProject="C:\Users\Gost\Desktop\SpringMvc+Spring+MyBatis+Maven\generator\generator\src">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
<!-- 要生成那些表(更改tableName和domainObjectName就能夠) -->
<table tableName="tuser" domainObjectName="User" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
<table tableName="tmenu" domainObjectName="Menu" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
<table tableName="tonline" domainObjectName="Online" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
<table tableName="tresource" domainObjectName="Resource" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
<table tableName="trole" domainObjectName="Role" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
<table tableName="tbug" domainObjectName="Bug" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
<table tableName="trole_tresource" domainObjectName="RoleResource" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
<table tableName="tuser_trole" domainObjectName="UserRole" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
</context>
</generatorConfiguration>java
3.而後創建空的src文件夾mysql
4.shift+右鍵在此位置運行(xp沒有此功能,只有在cmd中依次找到文件)執行語句sql
java -jar mybatis-generator-core-1.3.2.jar -configfile generator.xml -overwrite(在執行語句時注意你上面配置的一切路徑不要有中文,還有就是可能遇到老是報「前言中不容許有內容」的問題,解決方案:數據庫
用記事本打開xml文件轉化爲UTF-8會有一個BOM頭,因此java在讀取時就會報以上錯誤mybatis
解決方法:用notepad++打開,在格式選擇「以UTF-8無BOM格式編碼」,而後保存, 就能夠了app
)dom
完成代碼的自動生成工具
本人覺得generate工具大大提升了開發效率但願對你們有益編碼