MyBatis代码自动生成
MyBatis代码自动生成工具下载地址:
http://mybatis.googlecode.com/svn/sub-projects/generator/trunk/eclipse/UpdateSite/
使用方法:
1.在Eclipse中新建XML文件
1 <?xml version="1.0" encoding="UTF-8" ?> 2 <!DOCTYPE generatorConfiguration
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dt"> 3 <generatorConfiguration> 4 <properties resource="conf/jdbc.properties" /> 5 <!--连接数据库的jar包--> 6 <classPathEntry location="g:\ojdbc14_g.jar"/> 7 <context id="context1" targetRuntime="MyBatis3" defaultModelType="conditional"> 8 <commentGenerator> 9 <property name="suppressAllComments" value="true" /> 10 </commentGenerator> 11 <!--数据库连接配置--> 12 <jdbcConnection driverClass="${jdbc.driverClassName}" 13 connectionURL="${jdbc.url}" 14 userId="${jdbc.username}" 15 password="${jdbc.password}"/> 16 <!--model类生成位置--> 17 <javaModelGenerator targetPackage="cn.fenghuait.crm.model"
targetProject="erp/src/crm/java"/> 18 <!--sql文件生成位置--> 19 <sqlMapGenerator
targetPackage="cn.fenghuait.crm.dao.sql"
targetProject="erp/src/crm/java"/> 20 <!--dao文件生成位置--> 21 <javaClientGenerator
targetPackage="cn.fenghuait.crm.dao"
targetProject="erp/src/crm/java"
type="XMLMAPPER"/> 22 <!--数据库表--> 23 <table tableName="ERP_CUSTOMER_INFO" 24 domainObjectName="CustomerInfo" 25 enableCountByExample="false" 26 enableSelectByExample="false" 27 selectByExampleQueryId="false" 28 enableUpdateByExample="false" 29 enableDeleteByExample="false"> 30 <columnOverride column="CUST_ID" property="custId"></columnOverride> 31 <columnOverride column="COMPANY_NAME" property="companyName"></columnOverride> 32 <columnOverride column="ENGLISH_NAME" property="englishName"></columnOverride> 33 </table> 34 </context> 35 </generatorConfiguration>
2.利用工具自动生成代码