MBG-逆向工程

一、介绍

MBG:MyBatis Generator:代码生成器;

MyBatis官方提供的代码生成器;帮我们逆向生成;

正向:

table----javaBean---BookDao---dao.xml---xxx

逆向工程:

根据数据表table,逆向分析数据表,自动生成javaBean---BookDao---dao.xml---xxx


二、配置

1、导包:mbg的核心包

….. mybatis-generator-core-1.3.2.jar

2、编写mbg.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> <!--
MyBatis3Simple:基础班CRUD
MyBatis3:复杂版CRUD
-->
<context id="DB2Tables" targetRuntime="MyBatis3">
<commentGenerator>
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<!-- jdbcConnection:指导连接到哪个数据库 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/mybatis_0325" userId="root" password="123456">
</jdbcConnection> <javaTypeResolver>
<property name="forceBigDecimals" value="false" />
</javaTypeResolver> <!-- javaModelGenerator:生成pojo targetPackage:生成的pojo放在哪个包
targetProject:放在哪个工程下
-->
<javaModelGenerator targetPackage="com.atguigu.bean"
targetProject=".\src">
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
</javaModelGenerator> <!--sqlMapGenerator:sql映射文件生成器;指定xml生成的地方 -->
<sqlMapGenerator targetPackage="com.atguigu.dao"
targetProject=".\conf">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator> <!-- javaClientGenerator:dao接口生成的地方 -->
<javaClientGenerator type="XMLMAPPER"
targetPackage="com.atguigu.dao" targetProject=".\src">
<property name="enableSubPackages" value="true" />
</javaClientGenerator> <!-- table:指定要逆向生成哪个数据表
tableName="t_cat":表名
domainObjectName="":这个表对应的对象名
-->
<table tableName="t_cat" domainObjectName="Cat"></table>
<table tableName="t_employee" domainObjectName="Employee"></table>
<table tableName="t_teacher" domainObjectName="Teacher"></table> </context>
</generatorConfiguration>

三、测试

public class MBGTest {

    public static void main(String[] args) throws Exception {
List<String> warnings = new ArrayList<String>();
boolean overwrite = true;
File configFile = new File("mbg.xml");
ConfigurationParser cp = new ConfigurationParser(warnings);
Configuration config = cp.parseConfiguration(configFile);
DefaultShellCallback callback = new DefaultShellCallback(overwrite);
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config,
callback, warnings);
//代码生成
myBatisGenerator.generate(null);
System.out.println("生成ok了!");
} }

【串线篇】Mybatis拓展之MBG的更多相关文章

  1. MyBatis - Generator(MBG)

    前言 MyBatis Generator简称MBG,是一个专门为MyBatis框架使用者定制的代码生成器, 可以快速的根据数据表自动生成Bean对象.Java接口及SqlMapper.xml配置文件. ...

  2. 【串线篇】SpringBoot数据访问【数据源/mybatis/指定映射文件位置】

    一.配置数据源 1.1.jdbc版本 JDBC(.tomcat.jdbc.pool.DataSource作为数据源) <?xml version="1.0" encoding ...

  3. 【串线篇】Mybatis之SSM整合

    SSM:Spring+SpringMVC+MyBatis 建立Java web项目 一.导包 1).Spring: [aop核心] com.springsource.net.sf.cglib-2.2. ...

  4. 【串线篇】Mybatis缓存之整合第三方缓存

    为什么要用第三方缓存?因为mybatis的缓存机制说白了就是一个map,不够强大.但幸好mybatis有自知之明将其Cache做成了一个接口开放出来,我们可以实现这个接口用第三方专业的缓存框架去自定义 ...

  5. 【串线篇】Mybatis缓存之二级缓存

    1.应用 二级缓存:namespace级别的缓存:SqlSession关闭或者提交以后有效 一级缓存:SqlSession关闭或者提交以后,一级缓存的数据会放在二级缓存中: 二级缓存的使用:mybat ...

  6. 【串线篇】Mybatis缓存之一级缓存

    1.体会 一级缓存:MyBatis:SqlSesion级别的缓存:默认存在,不需要设置. 机制:只要之前查询过的数据,mybatis就会保存在一个缓存中(Map):下次获取直接从缓存中拿:当前sess ...

  7. 【串线篇】Mybatis缓存简介

    缓存:暂时的存储一些数据:加快系统的查询速度... CPU: 主频:4-2.7GHZ 内存:4G-8G    1333MHZ    2166MHZ CPU:一级缓存(4MB):二级缓存 (16MB); ...

  8. 【串线篇】Mybatis之动态sql

    一.if标签 <select id="getTeacherByCondition" resultMap="teacherMap"> select * ...

  9. 【串线篇】Mybatis入门

    MyBatis是持久化层框架(SQL映射框架)-操作数据库 一.环境搭建 1).创建一个java工程,java工程就行: 2). 创建表:自己用工具创建 创建javaBean:Employee(封装表 ...

随机推荐

  1. ckeditor粘贴word图片且图片文件自动上传功能

    自动导入Word图片,或者粘贴Word内容时自动上传所有的图片,并且最终保留Word样式,这应该是Web编辑器里面最基本的一个需求功能了.一般情况下我们将Word内容粘贴到Web编辑器(富文本编辑器) ...

  2. [NOIP2016][luogu]换教室[DP]

    [NOIP2016] Day1 T3 换教室 ——!x^n+y^n=z^n 题目描述 对于刚上大学的牛牛来说,他面临的第一个问题是如何根据实际情况申请合适的课程. 在可以选择的课程中,有 2n 节课程 ...

  3. BUUCTF | [De1CTF 2019]SSRF Me

    解法一字符串拼接: 1.得到签名sign http://8fa4531c-1164-49b7-a700-70e77e6aacb7.node3.buuoj.cn/geneSign?param=flag. ...

  4. 表单input中disabled提交后得不到值的解决办法

    input的字段当为diabled时时无法获取数值得,所以最近不要用这个,我们可以用readonly带替代,即可解决这类问题.  

  5. 1.安装TypeScrpit

    https://www.tslang.cn/index.html 1.vs安装 之前网上的查的安装方法是先安装nodejs,之后执行 npm install -g typescript 但是从官网的下 ...

  6. (appium+python)UI自动化_03_元素定位工具

    前言 在UI自动化过程中,需要对手机app上的元素进行定位,然后进一步编写自动化脚本操作app.定位元素首先需要定位工具来辅助查看页面元素.小编常用的定位工具有2种,分别是uiautomatorvie ...

  7. ECG 项目预研

    1. 数据的采集 智能安全帽,流数据,鉴于数据量大,应该是采集到云平台上,然后在云平台上对数据处理,是一种典型的物联网+大数据应用场景,考虑使用AWS或者阿里云,然后搭建Hadoop/Spark 环境 ...

  8. 有趣的linux指令

    1.cmatrix sudo apt-get update sudo apt-get install cmatrix 2.asciiquarium wget http://search.cpan.or ...

  9. 配置adb环境与简单命令

    adb命令具有安装卸载apk,拷贝推送文件,查看设备硬件信息,查看应用程序占用资源,在设备执行shell命令等 客户端:通过adb调用客户端 服务器server:运行后台,负责客户端与进程进行通信 守 ...

  10. php不支持多线程怎么办

    PHP 默认并不支持多线程,要使用多线程需要安装 pthread 扩展,而要安装 pthread 扩展,必须使用 --enable-maintainer-zts 参数重新编译 PHP,这个参数是指定编 ...