博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mybatis生成工具
阅读量:7209 次
发布时间:2019-06-29

本文共 2722 字,大约阅读时间需要 9 分钟。

hot3.png

一、MyBatisGeneratorConfig.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">

<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>

        <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类名 -->
        <!--合作伙伴-->

<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>
 

二、jar包

mybatis-generator-core-1.3.2.jar

mysql-connector-java-5.1.25.jar

 

三、使用命令

如果只想生成简单点的代码,比如没有动态查询的 在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
 

 

转载于:https://my.oschina.net/u/2322635/blog/1506040

你可能感兴趣的文章
快速用梯度下降法实现一个Logistic Regression 分类器
查看>>
python基础学习2
查看>>
[Tyvj 1728]普通平衡树
查看>>
css3
查看>>
table 中,如何使得单元格的内容不换行,单元格不被撑开
查看>>
Hibernate中session.get()和session.load()的区别
查看>>
泊松分布(Poisson distribution)的简单认识
查看>>
Android之使用传感器获取相应数据
查看>>
Jquery中html()方法 and "click"绑定后代元素
查看>>
HashMap和Hashtable的详细区别
查看>>
virutalbox虚拟机硬盘扩容
查看>>
自学计划
查看>>
dp-01背包问题 (升级)
查看>>
MySQL数据库唯一性设置(unique index)
查看>>
Windows性能计数器(命令行方式)
查看>>
Perl information,doc,module document and FAQ.
查看>>
sql 查询目标数据库中所有的表以其关键信息
查看>>
linux 下安装tomcat
查看>>
集成xadmin源码到项目的正式姿势
查看>>
自定义ViewPager,避免左右滑动时与水平滑动控件冲突
查看>>