mybatisGenerator自动生成pojo、dao、xml文件
一、简介:
mybatisGenerator是一款自动生成文件工具、本文使用idea2017.3.1来进行操作。
二、文件生成之后的项目结构:

三、开始生成步骤:
1、使用idea生成maven的结构
在idea中点击 file-->new-->project后出现如下界面
依次点击 maven-->Create from archetype(选择下面的archtype-webapp结尾的名字)-->next

点击next之后会出现如下界面、按照下面方式输入项目名等继续next

点击next后会出现如下界面
将两个方框打上√、选择maven的配置文件以及本地仓库。之后继续 next

会出现如下界面、之后点击finish普通的maven项目基本结构就已经生成了。

2、在 src/main目录下面新建 java 文件夹与 resources 文件夹
并将java文件夹标记为资源文件夹(右键java文件夹-->MarkDirectory as-->Sources Root)
将resources文件夹标记为资源文件夹(右键resources文件夹-->MarkDirectory as -->Resources Root)
3、在resources目录下新建 datasource.properites
# mybatisGenerator工具存放位置
db.driverLocation=d:/workspace/ideaWorkspace/Test/mysql-connector-java-5.1.6-bin.jar
# 数据库驱动
db.driverClassName=com.mysql.jdbc.Driver
# 数据库连接
db.url=jdbc:mysql://127.0.0.1:3306/ate?characterEncoding=utf-8 db.username=root
db.password=123456
在resources目录下新建 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>
<!--导入属性配置-->
<properties resource="datasource.properties"></properties> <!-- 指定数据库驱动的jdbc驱动jar包的位置 -->
<classPathEntry location="${db.driverLocation}"/> <!-- context 是逆向工程的主要配置信息 -->
<!-- id:起个名字 -->
<!-- targetRuntime:设置生成的文件适用于那个 mybatis 版本 -->
<context id="default" targetRuntime="MyBatis3"> <!--optional,旨在创建class时,对注释进行控制-->
<commentGenerator>
<property name="suppressDate" value="true"/>
<!-- 是否去除自动生成的注释 true:是 : false:否 -->
<property name="suppressAllComments" value="true"/>
</commentGenerator> <!--jdbc的数据库连接-->
<jdbcConnection driverClass="${db.driverClassName}"
connectionURL="${db.url}"
userId="${db.username}"
password="${db.password}">
</jdbcConnection> <!--非必须,类型处理器,在数据库类型和java类型之间的转换控制-->
<javaTypeResolver>
<!-- 默认情况下数据库中的 decimal,bigInt 在 Java 对应是 sql 下的 BigDecimal 类 -->
<!-- 不是 double 和 long 类型 -->
<!-- 使用常用的基本类型代替 sql 包下的引用类型 -->
<property name="forceBigDecimals" value="false"/>
</javaTypeResolver> <!-- targetPackage:生成的实体类所在的包 -->
<!-- targetProject:生成的实体类所在的硬盘位置 -->
<javaModelGenerator targetPackage="com.mall.pojo"
targetProject="./src/main/java">
<!-- 是否允许子包 -->
<property name="enableSubPackages" value="false"/>
<!-- 是否对modal添加构造函数 -->
<property name="constructorBased" value="true"/>
<!-- 是否清理从数据库中查询出的字符串左右两边的空白字符 -->
<property name="trimStrings" value="true"/>
<!-- 建立modal对象是否不可改变 即生成的modal对象不会有setter方法,只有构造方法 -->
<property name="immutable" value="false"/>
</javaModelGenerator> <!-- targetPackage 和 targetProject:生成的 mapper 文件的包和位置 -->
<sqlMapGenerator targetPackage="com.mall.mappers"
targetProject="./src/main/java">
<!-- 针对数据库的一个配置,是否把 schema 作为字包名 -->
<property name="enableSubPackages" value="false"/>
</sqlMapGenerator> <!-- targetPackage 和 targetProject:生成的 interface 文件的包和位置 -->
<javaClientGenerator type="XMLMAPPER"
targetPackage="com.mall.dao" targetProject="./src/main/java">
<!-- 针对 oracle 数据库的一个配置,是否把 schema 作为字包名 -->
<property name="enableSubPackages" value="false"/>
</javaClientGenerator>
<!--tableName:数据库对应表明 domainObjectName:pojo类名字-->
<table tableName="t_user" domainObjectName="User"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false">
</table>
</context>
</generatorConfiguration>
在pom.xml中的</pluginManagement>结尾标签中增加一段话
</pluginManagement>
<plugins>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
</plugin>
</plugins>
4、将工具放入指定的位置,与 datasource.properties 设置的路径要对应
5、开始生成,在 IDEA 左下角点击小电脑按钮,IDEA 界面两边会出现插件,单机右边的 Maven Projects,会出现如下界面,点击绿色开始,文件就会自动生成。

6、附上工具连接:https://pan.baidu.com/s/1qItkv28Ax10O3xSHak2UTQ 密码:b0ff
mybatisGenerator自动生成pojo、dao、xml文件的更多相关文章
- Java IDEA根据database以及脚本代码自动生成DO,DAO,SqlMapper文件(一)
根据数据库代码自动生成的插件挺多的,这里主要分享两种: 1.根据database以及脚本代码自动生成 2.根据mybatis-generator-core自动生成(下一章节进行分享,包含sqlserv ...
- mybatis自动生成mapper,dao映射文件
利用Mybatis-Generator来帮我们自动生成mapper.xml文件,dao文件,model文件. 1.所需文件 关于Mybatis-Generator的下载可以到这个地址:https:// ...
- mybatis-generator自动生成Mapper.dao.entity
在pom.xml中添加依赖 <plugin> <groupId>org.mybatis.generator</groupId> <artifactId> ...
- Mybatis 如何自动生成bean dao xml 配置文件 generatorconfig.xml (mysql)
1/自动生成的jar包:mybatis-generator-core-1.3.2.jar 2/generatorconfig.xml文件如: <?xml version="1.0& ...
- Mybatis 如何自动生成bean dao xml 配置文件 generatorconfig.xml (main()方法自动生成更快捷)
最近项目要用到mybatis中间件,中间涉及到要对表结构生成bean,dao,和sqlconfig.xml 所以记录一下学习过程 首先是准备工作,即准备需要的jar包:我们的数据库mysql,所以驱动 ...
- 使用IDEA springboot 如何通过mybatis-generator自动生成mapper dao model
第一步:在maven工程当中的resource下面,创建generatorConfig.xml文件. 务必注意创建的位置!!! <?xml version="1.0" enc ...
- hibernate tool连接oracle生成pojo和xml文件无法查询表解决办法
需要在hibernate的配置文件中增加 <property name="hibernate.default_schema">[username]</proper ...
- java web(七): mybatis的动态sql和mybatis generator自动生成pojo类和映射文件
前言: MyBatis 的强大特性之一便是它的动态 SQL.如果你有使用 JDBC 或其它类似框架的经验,你就能体会到根据 不同条件拼接 SQL 语句的痛苦.例如拼接时要确保不能忘记添加必要的空格,还 ...
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件(转)-----https://www.cnblogs.com/smileberry/p/4145872.html
https://www.cnblogs.com/smileberry/p/4145872.html 使用Mybatis-Generator自动生成Dao.Model.Mapping相关文件(转)
随机推荐
- consul之:ACL配置使用
consul自带ACL控制功能,看了很多遍官方文档,没有配置步骤https://www.consul.io/docs/internals/acl.html 主要对各种配置参数解释,没有明确的步骤,当时 ...
- Web jsp开发学习——点击菜单页面切换
两个网页使用同一个head,在点击“首页”后,head的“首页”变成绿色,点击“新闻”后,head的“新闻”变成绿色,head的“首页”恢复原来的颜色 head.jsp <%@ page ...
- kubernetes k8s yum localinstall
localinstall 是安装在本地的rpm包顺便解决依赖关系 yum localinstall docker-common-1.12.6-68.gitec8512b.el7.centos.x86_ ...
- WAL基础
WAL(Write-ahead logging,预写式日志)是数据库系统提供原子性和持久化的一系列技术. 在使用WAL的系统中,所有的修改都先被写入到日志中,然后再被应用到系统状态中.通常包含redo ...
- echart-map
1.非模块下引入地图: echarts.util.mapData.params.params.HK={ getGeoJson:function(callback){ $.getJSON('geoJso ...
- Opening socket connection to server :2181. Will not attempt to authenticate using SASL (unknown error) hbase
问题: 在HBase机群搭建完成后,通过jdbc连接hbase,在连接zookeeper阶段出现Opening socket connection to server :2181. Will not ...
- js之DOM
DOM对象 什么是HTML DOM HTML Document Object Model(文档对象模型) HTML DOM 定义了访问和操作HTML文档的标准方法 HTML DOM 把 HTML ...
- 17 RAID与mdadm管理命令
在"14 磁盘及文件系统管理详解"中,我们详细介绍了磁盘的工作原理,但是,有一点我们一定要明白,作为现在存储数据的主要设备,机械磁盘早就是上个世纪的产品,而它的读写速度与内存.CP ...
- 字符串切分 String.Split 和 Regex.Split(小技巧)
当切割字符串的是单个字符时可使用String.Split string strSample="ProductID:20150215,Categroy:Food,Price:15.00&quo ...
- is 和 == 区别,id() ,回顾编码,encode(),decode()
1. is 和 == 区别 id()函数 == 判断两边的值 is 判断内存地址例 s = "alex 是 大 xx"# abc = id(s) # 得到内存地址# print(a ...