MyBatis---使用MyBatis Generator生成Dto、Dao、Mapping
由于MyBatis属于一种半自动的ORM框架,所以主要的工作将是书写Mapping映射文件,但是由于手写映射文件很容易出错,
所以查资料发现有现成的工具可以自动生成底层模型类pojo类、Dao接口mapper类、甚至Mapping映射文件xml。
生成代码需要的文件和jar包:
(上图文件下载地址:http://download.csdn.net/detail/u012909091/7206091)
其中有mybatis框架的jar包,数据库驱动程序jar包以及MyBatis生成器jar包。其中的generatorConfig.xml是需要我们来配置的文件,配置如下:
随便从本地仓库找这几个jar,版本不同也没关系。

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>
<!--数据库驱动-->
<classPathEntry location="mysql-connector-java-5.1.6.jar"/>
<context id="DB2Tables" targetRuntime="MyBatis3">
<commentGenerator>
<property name="suppressDate" value="true"/>
<!--是否去除自动生成的注释 true:是 : false:否 -->
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<!--数据库链接URL,用户名、密码 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://192.168.0.82:13306/program_shopcart" userId="sa" password="">
</jdbcConnection>
<javaTypeResolver>
<property name="forceBigDecimals" value="false"/>
</javaTypeResolver>
<!--生成模型的包名和位置-->
<javaModelGenerator targetPackage="tb.db.mysql.shopcart.mybatis.pojo" targetProject="D:\temp\mysql_mybatis_shopcart">
<property name="enableSubPackages" value="true"/>
<property name="trimStrings" value="true"/>
</javaModelGenerator>
<!--生成映射文件的包名和位置-->
<sqlMapGenerator targetPackage="tb.db.mysql.shopcart.mybatis.xml" targetProject="D:\temp\mysql_mybatis_shopcart">
<property name="enableSubPackages" value="true"/>
</sqlMapGenerator>
<!--生成DAO的包名和位置-->
<javaClientGenerator type="XMLMAPPER" targetPackage="tb.db.mysql.shopcart.mybatis.mapper" targetProject="D:\temp\mysql_mybatis_shopcart">
<property name="enableSubPackages" value="true"/>
</javaClientGenerator>
<!-- 要生成的表 tableName是数据库中的表名或视图名 domainObjectName是实体类名-->
<table tableName="account_group" domainObjectName="Account_group" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
<table tableName="account_grouppermissionassign" domainObjectName="Account_grouppermissionassign" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
<table tableName="account_permission" domainObjectName="Account_permission" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
<table tableName="account_role" domainObjectName="Account_role" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
<table tableName="account_rolepermissionassign" domainObjectName="Account_rolepermissionassign" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
<table tableName="account_user" domainObjectName="Account_user" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
<table tableName="account_usergroupassign" domainObjectName="Account_usergroupassign" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
<table tableName="account_userpermissionassign" domainObjectName="Account_userpermissionassign" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
<table tableName="account_userroleassign" domainObjectName="Account_userroleassign" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
</context>
</generatorConfiguration>
1、生成mybatis文件(在IDEA的命令行里面执行)

java -jar mybatis-generator-core-1.4..jar -configfile generatorConfig.xml -overwrite

2、生成mybatis文件(在控制台里面执行),进入mybatis-generator-core-1.4.0.jar所在的目录下,执行脚本:
java -jar mybatis-generator-core-1.4.0.jar -configfile generatorConfig.xml -overwrite

生成好的文件存放在磁盘目录里




MyBatis---使用MyBatis Generator生成Dto、Dao、Mapping的更多相关文章
- mybatis generator.xml 配置 自动生成model,dao,mapping
generator.xml文件: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE gener ...
- MyBatis学习---使用MyBatis_Generator生成Dto、Dao、Mapping
由于MyBatis属于一种半自动的ORM框架,所以主要的工作将是书写Mapping映射文件,但是由于手写映射文件很容易出错,所以查资料发现有现成的工具可以自动生成底层模型类.Dao接口类甚至Mappi ...
- Mybatis 自动从数据库生成entity,mapping,dao接口
1.下载需要的jar包 mybatis-generator-core-1.3.2.jar,mysql-connector-java-5.1.39.jar 2.把上面的jar包放到某个目录,并在该目录下 ...
- mybatis自定义代码生成器(Generator)——自动生成model&dao代码
花了两天的时间研究了下mybatis的generator大体了解了其生成原理以及实现过程.感觉generator做的非常不错,给开发者也留足了空间.看完之后在generator的基础上实现了自定义的生 ...
- MyBatis generator 生成生成dao model mappper
MyBatis GeneratorXML配置文件参考 在最常见的用例中,MyBatis Generator(MBG)由XML配置文件驱动. 配置文件告诉MBG: 如何连接到数据库 什么对象要生成,以及 ...
- MyBatis Generator生成DAO——序列化
MyBatis Generator生成DAO 的时候,生成的类都是没有序列化的. 还以为要手工加入(開始是手工加入的),今天遇到分页的问题,才发现生成的时候能够加入插件. 既然分页能够有插件.序列化是 ...
- springboot学习随笔(四):Springboot整合mybatis(含generator自动生成代码)
这章我们将通过springboot整合mybatis来操作数据库 以下内容分为两部分,一部分主要介绍generator自动生成代码,生成model.dao层接口.dao接口对应的sql配置文件 第一部 ...
- mybatis Generator生成代码及使用方式
本文原创,转载请注明:http://www.cnblogs.com/fengzheng/p/5889312.html 为什么要有mybatis mybatis 是一个 Java 的 ORM 框架,OR ...
- Mybatis Generator生成工具配置文件详解
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE generatorConfiguration ...
随机推荐
- TeamView提示商业用途禁止使用
一.问题 TM被提示商业用途,用一会就断开连接,或者是提示五分钟后关闭 二.解决思路 2.1:删除原来的TM信息 首先需要卸载TM,其次需要去注册表,运行→regedit,打开注册表,删除相关的tea ...
- 关于 redis 报错 :JsonParseException: Unrecognized token 'xxx': was expecting ('true', 'false' or 'null')
在使用java 读取redis存储的数据时出现 JsonParseException: Unrecognized token 'xiaoqiang': was expecting ('true', ...
- BCG在程序中的使用
首先你电脑上是安装有BCG的,详细安装方法就是先双击安装程序,之后编译当中的两个project.之后将其生成的.dll\.lib文件放入C++的include中这样就能够使用BCG的控件了. 1. 在 ...
- IIS发布网站遇到 编译器错误消息: CS0016: 未能写入输出文件“c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary 编
编译错误: 说明:在编译向该请求提供服务所需资源的过程中出现错误.请检查下列特定错误详细信息并适当地修改源代码. 编译器错误消息:CS0016: 未能写入输出文件“c:\Windows\Microso ...
- GPUImage简单滤镜使用(二)
GPUImage中,提供了许多简单的的常用的滤镜.在上一篇文章讲了如何调节图像的亮度这片文章讲一下如何通过GPUImage调节图像的对比度,饱和度,曝光度,和白平衡(美图秀秀中的色温). 原图像 调整 ...
- 查看 js对象
for (var obj in data) { document.write( '|'+obj +'|'); };
- 从#!/bin/bash中想到的...
罪过罪过,开发了N年的SHELL,竟然第一次思考#!/bin/bash是啥意思?真是怀疑以前的的代码是咋开发出来的- 如果要解释#!/bin/bash是啥意思?为啥每个SHELL脚本第一行都写它哪?首 ...
- everything排除指定目录和文件
- thinkPHP 快速上手
http://www.kancloud.cn/manual/thinkphp5/118006 克隆项目 //首先克隆下载应用项目仓库 git clone https://github.com/top- ...
- Hadoop创建新用户
HDFS本身并没有提供用户名.组等的创建和管理,在客户端操作Hadoop时,Hadoop自动识别执行命令所在的进程的用户名和用户组,然后检查是否具有权限.启动Hadoop的用户即为超级用户,可以进行所 ...