mybatis生成工具

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&amp;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  

相关文章
相关标签/搜索