Help--Install new software--add
在弹出框中填入generator,地址是http://mybatis.googlecode.com/svn/sub-projects/generator/trunk/eclipse/UpdateSite/
然后选中搜索出的结果,下一步直到安装结束。
在src/main/resources下添加 名为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">
<!-- org.mybatis.generator:mybatis-generator-maven-plugin:1.3.1:generate -->
<generatorConfiguration>
<!-- 这里填个数据库连接器的jar包位置-->
<classPathEntry location="E:\jar\maven-repo\mysql\mysql-connector-java\5.1.27\mysql-connector-java-5.1.27.jar" />
<context id="DB2Tables" targetRuntime="MyBatis3">
<commentGenerator>
<property name="suppressDate" value="true" />
</commentGenerator>
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://IP:3307/custmis?useUnicode=true&characterEncoding=UTF-8" userId="admin" password="liantong">
</jdbcConnection>
<javaTypeResolver>
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<javaModelGenerator targetPackage="com.winksi.model"
targetProject="HistoryDataArrange">
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
</javaModelGenerator>
<sqlMapGenerator targetPackage="com.winksi.dao"
targetProject="HistoryDataArrange">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>
<javaClientGenerator type="XMLMAPPER"
targetPackage="com.winksi.dao" targetProject="HistoryDataArrange">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
<table tableName="cust_biz" domainObjectName="CustBiz"></table>
<table tableName="cust_biz_content" domainObjectName="CustBizContent"></table>
<table tableName="cust_biz_phone" domainObjectName="CustBizPhone"></table>
<table tableName="cust_biz_content_area" domainObjectName="CustBizContentArea"></table>
<table tableName="cust_biz_transfer_data" domainObjectName="CustBizTransferData"></table>
<table tableName="cust_biz_content_check" domainObjectName="CustBizContentCheck"></table>
<table tableName="cust_biz_stat" domainObjectName="CustBizStat"></table>
</context>
</generatorConfiguration>
然后再该配置文件上右键,Generator Mybatis/IBatis Aftifacts,刷新目录,即可看到生成的文件。
有时候会出现如下错误path for project must have only one segment
修改方法是,将targetProject改成项目的工程名,而不是src/main/java或../src/main/java