第一步:先下載jar包,mybatis-generator-core-1.3.2.jar, mysql-connector-java-5.1.13.jar;
第二步:編寫需要生成代碼的xml(根據實際的DB, 路徑編寫)
<?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="F:/mybatis/mysql-connector-java-5.1.13.jar"/>
<context id="my" targetRuntime="MyBatis3">
<commentGenerator>
<property name="suppressDate" value="false"/>
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://182.254.128.241:4780/product_wms_test" userId="cdb_outerroot"
password="zaq1CDE#"/>
<javaModelGenerator targetPackage="cn.eeka.productwms.entity.biz"
targetProject="F:/mybatis/wms/entity">
<property name="enableSubPackages" value="true"/>
<property name="trimStrings" value="true"/>
</javaModelGenerator>
<sqlMapGenerator targetPackage="mappers"
targetProject="F:/mybatis/wms/mapper">
<property name="enableSubPackages" value="true"/>
</sqlMapGenerator>
<javaClientGenerator targetPackage="cn.eeka.productwms.dao.biz"
targetProject="F:/mybatis/wms/dao" type="XMLMAPPER">
<property name="enableSubPackages" value="true"/>
</javaClientGenerator>
<table tableName="PM_ProductInBound" domainObjectName="ProductInBound"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false">
</table>
<table tableName="PM_ProductInBoundDetail" domainObjectName="ProductInBoundDetail"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false">
</table>
</context>
</generatorConfiguration>
第三步: 執行命令
打開命令窗口,切換到mybatis所在包的路徑下面,輸入命令: java -jar mybatis-generator-core-1.3.2.jar -configfile generatorConfig.xml -overwrite
或者 直接雙擊".bat"文件
注意: xml裏面涉及到的一些路徑配置,需要根據自己的實際情況填寫正確,
如果執行後出現報錯,一般有兩種原因:
a.把xml中的中文註釋都去掉;
b.把xml的編碼格式轉換成UTF-8 無BOM格式的;