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 ...
随机推荐
- ural2014 Zhenya moves from parents
Zhenya moves from parents Time limit: 1.0 secondMemory limit: 64 MB Zhenya moved from his parents’ h ...
- strace 分析 跟踪 进程错误
strace是什么? 按照strace官网的描述, strace是一个可用于诊断.调试和教学的Linux用户空间跟踪器.我们用它来监控用户空间进程和内核的交互,比如系统调用.信号传递.进程状态变更等. ...
- ionic常用命令记录
npm install -g ionic //安装ionic ionic lib update //更新www/lib/ionic 目录的文件,如有项目中有bower,此命令会运行bower upda ...
- 将一个字典内的内value转换为集合:返回一个数组,此数组中包含输入字典的键值对中的数组的所有元素(为NSArray添加category)
- (NSArray *)testa:(NSDictionary *)dic { NSMutableArray *arr_M = [NSMutableArray array]; // 1.遍历每一个元 ...
- 一种比较简单的在USB U盘中访问nandflash的方法
u8 nandflash_write_buffer[NAND_SERECT_FULL_SIZE]; static int currentBlock = -1; static int currentPa ...
- lpc1788IO口模拟IIC
#ifndef __MYIIC_H_ #define __MYIIC_H_ #include "common.h" #include "delay.h" #in ...
- Xcode6之后创建Pch预编译文件
在Xcode6之前,创建一个新工程xcode会在Supporting files文件夹下面自动创建一个“工程名-Prefix.pch”文件,也是一个头文件,pch头文件的内容能被项目中的其他所有源文件 ...
- phpcms替换来源
//替换来源:pc标签里面必须加moreinfo="1"不加会调不出来源 {pc:content action="lists" catid="12&q ...
- 只要单片机具有真正唯一ID,就可以让加密坚不可摧(转)
源:只要单片机具有真正唯一ID,就可以让加密坚不可摧 http://www.amobbs.com/thread-5518980-1-1.html 第一环:ID-->F1(ID) -----> ...
- 关于css中的border
我一直以为css中的border是正方形的 像这样 因为我平时用的时候都是 border:1px solid #000,都是同一个颜色所以看不出来 当我给每一个边分别设置颜色的时候才发现 他们是以梯形 ...