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了!");
} }

最新文章

  1. Guidelines for accessing OneDrive from an app
  2. as3 Loader 加载资源后内存泄露无法释放的问题。
  3. leetcode:Delete Node in a Linked List
  4. Codeforces Round #312 (Div. 2) A. Lala Land and Apple Trees 暴力
  5. python字符串格式化 %操作符 {}操作符---总结
  6. javascript原型链__proto__属性的理解
  7. CODING 敏捷实践完全指南
  8. 关于Django报错django.core.exceptions.ImproperlyConfigured: Requested setting DEBUG, but settings are not configure
  9. zoj 3605
  10. Linux shell编程 -test
  11. ionic2启动出现try again later
  12. No X11 DISPLAY variable was set
  13. RESTful规范1
  14. 通过JS页面唤醒app(安卓+ios)
  15. 一款超级炫酷的编辑代码的插件 Power Mode
  16. 【spring基础】spring声明式事务详解
  17. sql server 2008 数据库可疑的解决步骤
  18. Asp.Net MVC :路由器
  19. linux—文件目录简单介绍
  20. Thread中的join使用

热门文章

  1. 如何查看本机上安装的.NET Framework版本
  2. Python全栈开发,Day2
  3. asp.net开发微信公众平台----目录汇总-持续更新
  4. 当执行一条查询语句时,MySQL内部经历了什么?
  5. String 类的常用方法
  6. Log4j Threshold、Append
  7. Centos7配置定时重启服务器
  8. tp 框架目录结构
  9. Oracle11g安装步骤
  10. ELK+Filebeat (2)