MyBatis Generatorjava
一.mysql
下載 mybatis-generator-core-1.3.2.jar 以及 mysql-connector-java-5.1.26sql
下載地址: http://pan.baidu.com/s/1tlrx8 數據庫
二.mybatis
配置文件 generator.xmldom
<?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="mysql-connector-java-5.1.26.jar" /> <context id="MySQL" defaultModelType="flat" targetRuntime="MyBatis3"> <commentGenerator> <!-- 是否去除自動生成的註釋 true:是 : false:否 --> <property name="suppressAllComments" value="true" /> </commentGenerator> <!-- 數據庫鏈接信息:驅動類、URL、用戶名、密碼 --> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/mms" userId="root" password="root"></jdbcConnection> <javaTypeResolver> <property name="forceBigDecimals" value="false" /> </javaTypeResolver> <!-- 生成模型的包名和位置 --> <javaModelGenerator targetPackage="com.letv.mms.po" targetProject="E:\mms-common\src\main\java"> <property name="enableSubPackages" value="true" /> <property name="trimStrings" value="true" /> </javaModelGenerator> <!-- 生成的映射文件包名和位置 --> <sqlMapGenerator targetPackage=" MyBatis" targetProject="E:\mms-common\src\main\resources"> <property name="enalbeSubPackages" value="true" /> </sqlMapGenerator> <!-- 生成DAO的包名和位置 --> <javaClientGenerator type="XMLMAPPER" targetPackage="com.letv.mms.dao" targetProject="E:\mms-common\src\main\java"> <property name="enableSubPackages" value="true" /> </javaClientGenerator> <!-- 要生成哪此表(更改tableName和domainObjectName就能夠) --> <table tableName="t_video_info" domainObjectName="VideoPO" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table> <table tableName="t_album_info" domainObjectName="AlbumPO" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table> <table tableName="t_category_info" domainObjectName="CategoryPO" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table> <table tableName="t_property_info" domainObjectName="PropertyPO" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table> <table tableName="t_mms_info" domainObjectName="MmsPO" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table> </context> </generatorConfiguration>
幾個注意事項:ide
1.生成路徑請勿用中文,可能會有warning xxx does not existui
2.targetPackage不可爲空 異常:SQLMapGenerator Target Package is Required for contextspa
3.如遇其餘問題可查看Mybatis官方文檔 <generatorConfiguration>標籤code
三.運行腳本
java -jar mybatis-generator-core-1.3.2.jar -configfile generator.xml -overwrite
注意路徑問題 建議將Mybatis與MySQL的jar包放在同一文件夾下。