1、MyBatisGeneratorConfig.xml文件java
<?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">mysql
<generatorConfiguration>
<!-- jdbc驅動類的路徑 -->
<classPathEntry
location="E:\gitworkplace\mybatis_generate\mysql-connector-java-5.1.25.jar" />
<context id="mysqltables" targetRuntime="MyBatis3">
<!-- 去除自動生成的註釋 -->
<commentGenerator>
<property name="suppressAllComments" value="true" />
</commentGenerator>
<!-- 數據庫鏈接信息 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://192.168.1.98:3306/zd_maps_dev?useUnicode=true&characterEncoding=UTF-8"
userId="dev"
password="dev">
</jdbcConnection>git
<javaTypeResolver>
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!-- targetProject:自動生成代碼的存放位置 -->
<!-- 生成entity類 -->
<javaModelGenerator targetPackage="com.zdnst.biz.funeral.model.domain"
targetProject="E:\gitworkplace\maps-jushi\zdnst-common\zdnst-biz\biz-model\src\main\java">
<property name="enableSubPackages" value="false" />
<!-- 是否針對string類型的字段在set的時候進行trim調用 -->
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!-- 生成mybatis的xml映射文件 -->
<sqlMapGenerator targetPackage="mappings"
targetProject="E:\gitworkplace\maps-jushi\zdnst-common\zdnst-biz\biz-model\src\main\resources">
<property name="enableSubPackages" value="false" />
</sqlMapGenerator>
<!-- 生成Mapper接口(即DAO接口) -->
<javaClientGenerator type="XMLMAPPER"
targetPackage="com.zdnst.biz.funeral.model.mapper" targetProject="E:\gitworkplace\maps-jushi\zdnst-common\zdnst-biz\biz-model\src\main\java">
<property name="enableSubPackages" value="false" />
</javaClientGenerator>
<!-- 指定表和實體類的具體映射信息 -->
<!-- tableName:用於自動生成代碼的數據庫表;domainObjectName:對應於數據庫表的javaBean類名 -->
<!--合做夥伴-->sql
<table tableName="ju_fn_funeral" domainObjectName="Funeral" enableSelectByExample="false" enableDeleteByExample="false" enableCountByExample="false" enableUpdateByExample="false" selectByExampleQueryId="false"> <property name="useActualColumnNames" value="true" /> </table>數據庫
</context>
</generatorConfiguration>
mybatis
2、jar包app
mybatis-generator-core-1.3.2.jardom
mysql-connector-java-5.1.25.jar插件
3、使用命令命令行
若是隻想生成簡單點的代碼,好比沒有動態查詢的 在table元素的屬性中有幾個屬性應該設置爲false,示例以下:
enableSelectByExample="false"
enableDeleteByExample="false"
enableCountByExample="false"
enableUpdateByExample="false"
selectByExampleQueryId="false"
配置文件弄好生成代碼有多種方式,能夠用命令行、ant、插件等方式來生成,命令行生成方式示例以下 (主要是制定jar路徑和配置文件路徑): java -jar E:\\gitworkplace\\mybatis_generate\\mybatis-generator-core-1.3.2.jar -configfile E:\\gitworkplace\\mybatis_generate\\MyBatisGeneratorConfig.xml -overwrite