Mybatis -代码自动生成(generatorConfig.xml)
参考:http://blog.csdn.net/jinshiyill/article/details/51546676
官方网址: http://www.mybatis.org/generator/configreference/xmlconfig.html
原码:http://download.csdn.net/detail/wangxy799/9773975
1. 环境:
Maven 3.39
Oracle 11g
Mybatis 3.4.1
Maven project
2. 目录结构
3. pom添加插件
<dependencies>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- mybatis-generator自动生成代码插件 -->
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.5</version>
</plugin>
</plugins>
</build>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
4. 新建generatorConfig.xml 文件(放在src/main/resources目录下)
<?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="application.properties"/>
<!-- 指定数据库连接驱动jara地址 -->
<classPathEntry
location="${generator.location}" />
<!-- 一个数据库一个context -->
<context id="sqlserverTables">
<!-- 生成的pojo,将implements Serializable -->
<plugin type="org.mybatis.generator.plugins.SerializablePlugin"></plugin>
<!-- 注释 -->
<commentGenerator>
<property name="suppressAllComments" value="true" /><!-- 是否取消注释 -->
<!-- <property name="suppressDate" value="true" /> 是否生成注释代时间戳 -->
</commentGenerator>
<!-- 数据库链接URL、用户名、密码 -->
<jdbcConnection driverClass="${db.example.driver}"
connectionURL="${db.example.url}" userId="${db.example.username}"
password="${db.example.password}">
</jdbcConnection>
<!-- 类型转换 -->
<javaTypeResolver>
<!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer true,把JDBC DECIMAL
和 NUMERIC 类型解析为java.math.BigDecimal -->
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!-- 生成model模型,对应的包路径,以及文件存放路径(targetProject),targetProject可以指定具体的路径,如./src/main/java,
也可以使用“MAVEN”来自动生成,这样生成的代码会在target/generatord-source目录下 -->
<javaModelGenerator targetPackage="${generator.targetPackage}"
targetProject="./src/main/java">
<!-- 是否在当前路径下新加一层schema,eg:fase路径com.oop.eksp.user.model, true:com.oop.eksp.user.model.[schemaName] -->
<property name="enableSubPackages" value="false" />
<!-- 从数据库返回的值被清理前后的空格 -->
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!--对应的mapper.xml文件 -->
<sqlMapGenerator targetPackage="${generator.targetPackage}"
targetProject="./src/main/java">
<property name="enableSubPackages" value="false" />
</sqlMapGenerator>
<!-- 对应的Mapper接口类文件 -->
<javaClientGenerator type="XMLMAPPER"
targetPackage="${generator.targetPackage}" targetProject="./src/main/java">
<property name="enableSubPackages" value="false" />
</javaClientGenerator>
<!-- 列出要生成代码的所有表,这里配置的是不生成Example文件 -->
<!-- schema即为数据库名 tableName为对应的数据库表 domainObjectName是要生成的实体类 enable*ByExample
是否生成 example类 -->
<table tableName="${gererator.tableName}" domainObjectName="${gererator.objectName}"
schema="${gererator.schema}"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false">
<!-- 忽略列,不生成bean 字段
<ignoreColumn column="FRED" />-->
<!-- 指定列的java数据类型
<columnOverride column="LONG_VARCHAR_FIELD" jdbcType="VARCHAR" /> -->
<!-- 用于指定生成实体类时是否使用实际的列名作为实体类的属性名。false是 Camel Case风格-->
<property name="useActualColumnNames" value="false" />
</table>
</context>
</generatorConfiguration>
- 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
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
5. 设置需要生成的表及创建目录参数(application.properties放在src/main/resources目录下)
db.example.type=oracle
db.example.driver=oracle.jdbc.driver.OracleDriver
db.example.url=jdbc:oracle:thin:@ip:port:sid
db.example.username=username
db.example.password=password
#MBGInfo
generator.location=D:/project/eas_std/BaseApp/lib/ojdbc14-10.2.0.5.jar
generator.targetPackage=com.zteict.example.menu
gererator.schema=fbp
gererator.tableName=fbp_menu
gererator.objectName=FbpMenu
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
6. 项目右键-RUN AS-MAVEN BUILD..
输入 mybatis-generator:generate
7. 生成的文件
FbpMenu:
FbpMenuMapper:
Xml:
Mybatis -代码自动生成(generatorConfig.xml)的更多相关文章
- Mybatis 代码自动生成(generatorConfig.xml配置)
博客推荐: Mybatis最入门---代码自动生成(generatorConfig.xml配置) MyBatis Generator generatorConfig.xml配置详解 pom.xml&l ...
- MyBatis代码自动生成(利用命令)
这几天在学习springmvc,需要用到mybatis,所以研究了一下mybatis自动代码生成,当然也可以手动敲,但是那样效率非常的慢,并且出错率也是很高的,利用MyBatis生成器自动生成实体类. ...
- MyBatis代码自动生成
MyBatis的代码自动生成的功能,由于MyBatis属于一种半自动的ORM框架,所以主要的工作就是配置Mapping映射文件,但是由于手写映射文件很容易出错,所以可利用MyBatis生成器自动生成实 ...
- Spring Boot (七)MyBatis代码自动生成和辅助插件
一.简介 1.1 MyBatis Generator介绍 MyBatis Generator 是MyBatis 官方出品的一款,用来自动生成MyBatis的 mapper.dao.entity 的框架 ...
- Mybatis 代码自动生成[myeclipse版]
使用环境说明: OS:windows 7 64位 myeclipse: 2017 CI 1.安装 打开myeclipse--help---Install from catalog--选择eclipse ...
- eclipse生成mybatis的逆向工程-mybatis代码自动生成
首先,工作中一直在使用命令方式的mybatis的代码自动生成,今天把自己的笔记本直接搞一个在eclipse中生成的逆向代码生成工程,方便自己在家学习使用,在搞这个工程的过程中由于自己搞了一套环境,所i ...
- Mybatis代码自动生成(含测试)
一.建立数据库 create database shixun; use shixun; create table user( id int primary key auto_increment , u ...
- mybatis-generator-gui--一个mybatis代码自动生成界面工具
mybatis-generator-gui是什么 介绍mybatis-generator-gui之前,有必要介绍一下什么是mybatis generator(熟悉的同学可以跳过这一节).我们都知道,通 ...
- Mybatis代码自动生成插件使用
1.配置pom.xml 添加mybatis-generator-maven-plugin到pom.xml. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 1 ...
随机推荐
- P2S、P2P、P2SP之对比
P2S.P2P.P2SP之对比 一.下载原理分析 1.服务端下载技术(P2S):P2S下载方式分为HTTP与FTP两种类型,它们分别是Hyper Text Transportation Protoco ...
- [Scala]Scala学习笔记七 正则表达式
1. Regex对象 我们可以使用scala.util.matching.Regex类使用正则表达式.要构造一个Regex对象,使用String类的r方法即可: val numPattern = &q ...
- 算法训练 P1102
算法训练 P1102 时间限制:1.0s 内存限制:256.0MB 定义一个学生结构体类型student,包括4个字段,姓名.性别.年龄和成绩.然后在主函数中定义一个结构体数组( ...
- Qemu编译qemu-system-arm
/********************************************************************************* * Qemu编译qemu-syst ...
- Ubuntu 18.10 安装PDF阅读器
======================================== 软件开发转移到了 Linux上,使用Ubuntu 18.10作为桌面开发环境 下面介绍 安装PDF阅读器 1.下载 福 ...
- Word所有字体按比例缩小
ctrl + [ 不然每次都要一部分一部分的修改啊
- poj2253 最短路
题意:青蛙跳石头,给出石头的坐标,然后要确定一条路径,使路径上的最大跨度最小,其实也是一道最短路问题,只要将更新条件从总距离最短改为最大跨度最小就行,即从某点到当前点路径上的最大跨度如果小于当前点原本 ...
- Html页面Dom对象之Document
Document 对象 每个载入浏览器的 HTML 文档都会成为 Document 对象. Document 对象使我们可以从脚本中对 HTML 页面中的所有元素进行访问. 提示:Document 对 ...
- vulcanjs schemas&& collections
一张参考图 说明 从上图我们可以方便的看出schmea 能做的事情 Generate a GraphQL equivalent of your schema to control your Graph ...
- Vquery PHP 简单爬虫类
http://www.thinkphp.cn/topic/36693.html 在使用php进行网页抓取的时候你有没有感觉到用起来比较麻烦呢?目前我还没有发现php有这样针对网页抓取的类,每次用到这个 ...