MyBatis-Generator的配置说明和使用
关于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的配置说明和使用的更多相关文章
- JAVA入门[7]-Mybatis generator(MBG)自动生成mybatis代码
一.新建测试项目 新建Maven项目MybatisDemo2,修改pom.xml引入依赖.dependencies在上节基础上新增 <dependency> <groupId> ...
- mybatis Generator生成代码及使用方式
本文原创,转载请注明:http://www.cnblogs.com/fengzheng/p/5889312.html 为什么要有mybatis mybatis 是一个 Java 的 ORM 框架,OR ...
- 使用MyBatis Generator自动创建代码(dao,mapping,poji)
连接的数据库为SQL server2008,所以需要的文件为sqljdbc4.jar 使用的lib库有: 在lib库目录下新建一个src文件夹用来存放生成的文件,然后新建generatorConfig ...
- mybatis generator 自动生成dao层映射代码
资源: doc url :http://www.mybatis.org/generator/ download:https://github.com/mybatis/generator/release ...
- mybatis generator maven插件自动生成代码
如果你正为无聊Dao代码的编写感到苦恼,如果你正为怕一个单词拼错导致Dao操作失败而感到苦恼,那么就可以考虑一些Mybatis generator这个差价,它会帮我们自动生成代码,类似于Hiberna ...
- mybatis generator.xml 配置 自动生成model,dao,mapping
generator.xml文件: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE gener ...
- Mybatis generator的使用
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE generatorConfiguration ...
- MyBatis Generator作为maven插件自动生成增删改查代码及配置文件例子
什么是MyBatis Generator MyBatis Generator (MBG) 是一个Mybatis的代码生成器,可以自动生成一些简单的CRUD(插入,查询,更新,删除)操作代码,model ...
- 记一次 IDEA mybatis.generator 自定义扩展插件
在使用 idea mybatis.generator 生成的代码,遇到 生成的代码很多重复的地方, 虽然代码是生成的,我们也不应该允许重复的代码出现,因为这些代码后期都要来手动维护. 对于生成时间戳注 ...
- Mybatis Generator生成工具配置文件详解
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE generatorConfiguration ...
随机推荐
- CSS实现三角形方法二--border+content
方法说明: 1.将一个div块的内容设置为空(content=" "), 2.设置它的边框(上下左右)颜色为透明(transparent), 3.设置它的左侧边框颜色为pink. ...
- (中等) CF 555E Case of Computer Network,双连通+树。
Andrewid the Android is a galaxy-known detective. Now he is preparing a defense against a possible a ...
- 我收藏的Blog
收集我开发过程中遇见的优秀Blog iOS圈 王巍-强烈推荐 唐巧-强烈推荐 YYKit作者-强烈推荐 Imrazor's Blog Ryan's Zone http://www.cnblogs.co ...
- javadoc时候乱码-编码 GBK 的不可映射字符 - wqjsir的专栏 - 博客频道 - CSDN.NET
body { font-family: "Microsoft YaHei UI","Microsoft YaHei",SimSun,"Segoe UI ...
- Spring自学教程-AOP学习(五)
Spring中的AOP 一.概述 (一)基本概念 1.什么是AOP? 面向方面编程.所谓方面即是指日志.权限.异常处理.事务处理等. 2.AOP的3个关键概念 (1)切入点(Pointc ...
- mysql 查找重复的数据
Select Name,Count(*) From A Group By Name Having Count(*) > 1 Name是字段
- CodeForces 631C Print Check
排序+构造+预处理 #include<cstdio> #include<cstring> #include<cmath> #include<algorithm ...
- ajax--2017年1月15日
听说点六下就能复制了? ajax: 一般处理程序(数据接口):ashx 跨语言传递数据:xml: 结构不清晰 代码量比较大 查找起来比较费事 非面向对象结构 json: 结构清晰 代码量相对较小 面向 ...
- collectionviewcell 添加删除按钮 响应区域的问题
在collectionviewcell 的右上角添加了一个删除按钮,但是发现只有cell和删除按钮重合的区域才会响应点击事件 后来doctor 李说这是iOS 事件响应链的机制(http://www. ...
- dom4j生成和解析xml文件
dom4j生成和解析xml文件 要生成和解析如下格式的xml文件: <?xml version="1.0" encoding="UTF-8"?> & ...