关于MyBatis:

  MyBatis Generator (MBG) 是一个Mybatis的代码生成器 MyBatis 和 iBATIS. 他可以生成Mybatis各个版本的代码,和iBATIS 2.2.0版本以后的代码。 他可以内省数据库的表(或多个表)然后生成可以用来访问(多个)表的基础对象。 这样和数据库表进行交互时不需要创建对象和配置文件。 MBG的解决了对数据库操作有最大影响的一些简单的CRUD(插入,查询,更新,删除)操作。

准备工作:

  下载MyBatis-Generator 点击此处下载

下载成功以后 如下图

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

    <!--
        在此处修改数据库的驱动包   必须提前将驱动包放到本配置文件的同级目录下 笔者已提前放好
        如使用Oracle数据库时 <classPathEntry location="oracle.jar" />
    -->
    <classPathEntry location="mysql.jar" />

    <context id="DB2Tables" targetRuntime="MyBatis3">
        <commentGenerator>
            <property name="suppressAllComments" value="true" />     <!-- 是否取消注释 -->
            <property name="suppressDate" value="true" />             <!-- 是否生成注释代时间戳 -->
        </commentGenerator>

        <!-- 此处修改数据库的连接信息 -->
        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
            connectionURL="jdbc:mysql://localhost:3306/easybuy" userId="root"
            password="pengxiongpengdi" />

        <javaTypeResolver>
            <property name="forceBigDecimals" value="false" />
        </javaTypeResolver>

        <!--
            要生成的实体类
            每个项目包的命名 都不一样 可以通过修改 该属性 实现
            targetPackage="com.buy.entity"
         -->
        <javaModelGenerator targetPackage="com.buy.entity"
            targetProject="src">
            <property name="enableSubPackages" value="true" />
            <property name="trimStrings" value="true" />
        </javaModelGenerator>
        <!-- 要生成的接口 -->
        <sqlMapGenerator targetPackage="com.buy.dao"
            targetProject="src">
            <property name="enableSubPackages" value="true" />
        </sqlMapGenerator>
        <!-- 要生成的映射文件 -->
        <javaClientGenerator type="XMLMAPPER"
            targetPackage="com.buy.dao" targetProject="src">
            <property name="enableSubPackages" value="true" />
        </javaClientGenerator>

        <!--
            配置要映射的表
            数据库中对应的表:      tableName="EASYBUY_PRODUCT"
            项目中实体类的名字:    domainObjectName="ProductEntity"
            其他属性默认即可
        -->
        <table tableName="EASYBUY_PRODUCT" domainObjectName="ProductEntity"
            enableCountByExample="false" enableUpdateByExample="false"
            enableDeleteByExample="false" enableSelectByExample="false"
            selectByExampleQueryId="false"></table>
        <table tableName="EASYBUY_PRODUCT_CATEGORY" domainObjectName="CategoryEntity"
            enableCountByExample="false" enableUpdateByExample="false"
            enableDeleteByExample="false" enableSelectByExample="false"
            selectByExampleQueryId="false"></table>
        <table tableName="EASYBUY_USER" domainObjectName="UserEntity"
            enableCountByExample="false" enableUpdateByExample="false"
            enableDeleteByExample="false" enableSelectByExample="false"
            selectByExampleQueryId="false"></table>
    </context>
</generatorConfiguration>

配置好以后 运行go.cmd  src目录下 就会生成 对应的接口、映射文件和实体类

此时 就生成 完毕了 可以在此基础上 添加其他功能

MyBatis-Generator的配置说明和使用的更多相关文章

  1. JAVA入门[7]-Mybatis generator(MBG)自动生成mybatis代码

    一.新建测试项目 新建Maven项目MybatisDemo2,修改pom.xml引入依赖.dependencies在上节基础上新增 <dependency> <groupId> ...

  2. mybatis Generator生成代码及使用方式

    本文原创,转载请注明:http://www.cnblogs.com/fengzheng/p/5889312.html 为什么要有mybatis mybatis 是一个 Java 的 ORM 框架,OR ...

  3. 使用MyBatis Generator自动创建代码(dao,mapping,poji)

    连接的数据库为SQL server2008,所以需要的文件为sqljdbc4.jar 使用的lib库有: 在lib库目录下新建一个src文件夹用来存放生成的文件,然后新建generatorConfig ...

  4. mybatis generator 自动生成dao层映射代码

    资源: doc url :http://www.mybatis.org/generator/ download:https://github.com/mybatis/generator/release ...

  5. mybatis generator maven插件自动生成代码

    如果你正为无聊Dao代码的编写感到苦恼,如果你正为怕一个单词拼错导致Dao操作失败而感到苦恼,那么就可以考虑一些Mybatis generator这个差价,它会帮我们自动生成代码,类似于Hiberna ...

  6. mybatis generator.xml 配置 自动生成model,dao,mapping

    generator.xml文件: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE gener ...

  7. Mybatis generator的使用

    <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE generatorConfiguration ...

  8. MyBatis Generator作为maven插件自动生成增删改查代码及配置文件例子

    什么是MyBatis Generator MyBatis Generator (MBG) 是一个Mybatis的代码生成器,可以自动生成一些简单的CRUD(插入,查询,更新,删除)操作代码,model ...

  9. 记一次 IDEA mybatis.generator 自定义扩展插件

    在使用 idea mybatis.generator 生成的代码,遇到 生成的代码很多重复的地方, 虽然代码是生成的,我们也不应该允许重复的代码出现,因为这些代码后期都要来手动维护. 对于生成时间戳注 ...

  10. Mybatis Generator生成工具配置文件详解

    <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE generatorConfiguration ...

随机推荐

  1. Android Studio的使用(四)--生成Get、Set方法

    如何快速生成Get.Set方法,在我们编程中经常使用,下面将详细介绍. 1.右击代码编辑区域,并选择Generate. 2.在弹出框中选择Getter and Setter. 3.在弹出框中全选所有变 ...

  2. Struts2--Action属性接收参数

    1. JSP文件调用格式: <a href="user/user!add?name=a&age=8">添加用户</a> 2. struts.xml文 ...

  3. WEB网页输入框的默认键盘类型控制

    参考资料 http://www.w3school.com.cn/html5/att_input_type.asp : 语法 <input type="value"> 属 ...

  4. php的几个内置的函数

    // 取得所有的后缀为PHP的文件 $files = glob(‘*.php’); print_r($files); j

  5. 多年心愿,终于完成,热泪盈眶啊。。。Adrew NG 的 机器学习

    谢谢Andrew老师!谢谢Coursera!谢谢自己!希望这是一个好的开始!希望自己也能使用机器学习来make a better world...  

  6. 浅谈mysql主从复制的高可用解决方案

    1.熟悉几个组件(部分摘自网络)1.1.drbd     —— DRBD(Distributed Replicated Block Device),DRBD号称是 "网络 RAID" ...

  7. Jquery使用常见(全)

    一.选择器实例 语法 描述 $(this) 当前 HTML 元素 $("p") 所有 <p> 元素 $("p.intro") 所有 class=&q ...

  8. 设置MyEclipse黑色主题背景

    设置MyEclipse黑色主题背景 1. 下载 http://eclipsecolorthemes.org/  看哪个合适直接点击进入, 下载右边的epf 2. 下载完成...打开myeclipse. ...

  9. 安装arm-linux-gcc交叉编译器

    1.开发平台 虚拟机:VMware 12 操作系统:Ubuntu 14.04 2.准备交叉编译工具包(arm-linux-gcc-4.5.1) 编译uboot和linux kernel都需要gnu交叉 ...

  10. Scott用户的四张表:

    Scott用户的四张表: 转载:http://www.cnblogs.com/mchina/archive/2012/09/06/2649951.html 在Oracle的学习之中,重点使用的是SQL ...