mybatis開發輔助工具,生成model類、dao接口類和mapping映射文件,具體用法以下,註釋很詳細,
html
generator.xmljava
<?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\Administrator\.m2\repository\mysql\mysql-connector-java\5.1.6\mysql-connector-java-5.1.6.jar" /> <!-- <classPathEntry location="C:\oracle\product\10.2.0\db_1\jdbc\lib\ojdbc14.jar" /> --> <context id="DB2Tables" targetRuntime="MyBatis3"> <commentGenerator> <property name="suppressAllComments" value="true" /> </commentGenerator> <!-- 數據庫連接URL、用戶名、密碼 --> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://192.168.191.1:3306/xuebaodb" userId="root" password="root"> <!--<jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver" connectionURL="jdbc:oracle:thin:@localhost:1521:orcl" userId="msa" password="msa"> --> </jdbcConnection> <javaTypeResolver> <property name="forceBigDecimals" value="false" /> </javaTypeResolver> <!-- 生成實體類的包名和位置,這裏配置將生成的實體類放在me.gacl.domain這個包下 --> <javaModelGenerator targetPackage="me.gacl.domain" targetProject="C:\Users\Administrator\Workspaces\MyEclipse10.redismaven\spring4-mybatis3 Maven Webapp\src\main\java"> <property name="enableSubPackages" value="true" /> <property name="trimStrings" value="true" /> </javaModelGenerator> <!-- 生成的SQL映射文件包名和位置,這裏配置將生成的SQL映射文件放在me.gacl.mapping這個包下 --> <sqlMapGenerator targetPackage="me.gacl.mapping" targetProject="C:\Users\Administrator\Workspaces\MyEclipse10.redismaven\spring4-mybatis3 Maven Webapp\src\main\java"> <property name="enableSubPackages" value="true" /> </sqlMapGenerator> <!-- 生成DAO的包名和位置,這裏配置將生成的dao類放在me.gacl.dao這個包下 --> <javaClientGenerator type="XMLMAPPER" targetPackage="me.gacl.dao" targetProject="C:\Users\Administrator\Workspaces\MyEclipse10.redismaven\spring4-mybatis3 Maven Webapp\src\main\java"> <property name="enableSubPackages" value="true" /> </javaClientGenerator> <!-- 要生成那些表(更改tableName和domainObjectName就能夠) --> <table tableName="t_user" domainObjectName="User" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" /> </context> </generatorConfiguration>
執行命令以下:
mysql
java -jar mybatis-generator-core-1.3.2.jar -configfile generator.xml -overwrite
給出mybatis-generator-core-1.3.2.jar下載地址:
redis
http://pan.baidu.com/s/1bnmERvx spring
轉載一篇修改generator的文章:sql
http://www.blogjava.net/bolo/archive/2015/03/20/423683.html 數據庫