关于MyBatis:
MyBatis Generator (MBG) 是一个Mybatis的代码生成器 MyBatis 和 iBATIS. 他可以生成Mybatis各个版本的代码,和iBATIS 2.2.0版本以后的代码。 他可以内省数据库的表(或多个表)然后生成可以用来访问(多个)表的基础对象。 这样和数据库表进行交互时不需要创建对象和配置文件。 MBG的解决了对数据库操作有最大影响的一些简单的CRUD(插入,查询,更新,删除)操作。
准备工作:
下载MyBatis-Generator 点击此处下载
下载成功以后 如下图
generatorConfig.xml是核心配置文件,主要内容与解释如下
?
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
<?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目录下就会生成 对应的接口、映射文件和实体类
此时就生成完毕了可以在此基础上添加其他功能
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持快网idc!
原文链接:http://www.cnblogs.com/hnlictmso/p/6308664.html
相关文章
猜你喜欢
- 64M VPS建站:怎样选择合适的域名和SSL证书? 2025-06-10
- 64M VPS建站:怎样优化以提高网站加载速度? 2025-06-10
- 64M VPS建站:是否适合初学者操作和管理? 2025-06-10
- ASP.NET自助建站系统中的用户注册和登录功能定制方法 2025-06-10
- ASP.NET自助建站系统的域名绑定与解析教程 2025-06-10
TA的动态
- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
- 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
- 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
- 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
- 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
快网idc优惠网
QQ交流群
您的支持,是我们最大的动力!
热门文章
-
2025-05-27 85
-
2025-06-04 98
-
2025-05-29 11
-
2025-05-29 74
-
使用递归删除树形结构的所有子节点(java和mysql实现)
2025-05-29 33
热门评论



