mybatis反向工程
首先创建一个test类:
在main方法里写上如下代码:
List <String> warnings = new ArrayList <String>();
boolean overwrite = true;
File configFile = new File("generator.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);
在工程目录下新建一个generator.xml文件:
开发工具eclipse:

开发工具idea:

<?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> <context id="DB2Tables" targetRuntime="MyBatis3"> <commentGenerator>
<property name="suppressAllComments" value="true"></property>
</commentGenerator> <!-- 设定数据库连接 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/mybatis"
userId="root"
password="123">
</jdbcConnection> <javaTypeResolver >
<property name="forceBigDecimals" value="false" />
</javaTypeResolver> <!-- 生成 bean 存放的位置 -->
<javaModelGenerator targetPackage="com.ujiuye.bean" targetProject=".\src">
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
</javaModelGenerator> <!-- 生成的mapper文件的位置 -->
<sqlMapGenerator targetPackage="com.ujiuye.mapper" targetProject=".\src">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator> <!-- 生成的mapper.xml 对应的那个mapper接口的存放位置 -->
<javaClientGenerator type="XMLMAPPER" targetPackage="com.ujiuye.mapper" targetProject=".\src">
<property name="enableSubPackages" value="true" />
</javaClientGenerator> <!-- 设定反向生成的表 -->
<table tableName="Person"></table>
<table tableName="car"></table>
<table tableName="card"></table> </context>
</generatorConfiguration>
最后的table标签是自己数据库中表的名字;数据库的连接信息需要自己修改
执行test类就会自动生成自己以上设置table标签中数据中表的对应的实体类,dao层接口以及对应的mapper映射
此外需要的jar包请自行下载:https://github.com/Pei-Qi/mybatis_jar

mybatis反向工程的更多相关文章
- IntelliJ IDEA 2017版 spring-boot2.0.4+mybatis反向工程;mybatis+springboot逆向工程
一.搭建环境 采用IDE自动建立项目方式 然后,next next,配置导入依赖包 项目就生成了,在项目下导入配置文件GeneratorMapper.xml(项目结构如图所示) 配置文档,建立数据库和 ...
- 基于SSM的租赁管理系统1.0_20161225_框架搭建
搭建SSM底层框架 1. 利用mybatis反向工程generatorSqlmapCustom完成对数据库十表的映射 generatorConfig.xml <?xml version=&quo ...
- SSM整合案例
使用IDEA整合SSM spring核心配置文件:beans_core.xml/applicationContext.xml <?xml version="1.0" enco ...
- 整合spring roo,maven,mybatis,spring-flex,blazeds,mysql
1. 下载spring roo,设置环境变量ROO_HOME,和path,classpath. 使用CMD命令行找到工作区间,新建工程目录转到工程目录:mkdir ten-minutes $ ...
- SpringMVC,MyBatis商品的增删改查
一.需求 商品的增删改查 二.工程结构 三.代码 1.Mapper层 (1) ItemsMapperCustom.java package com.tony.ssm.mapper; import ja ...
- springboot第一个项目【mybatis】
1.resources下添加spring 添加spring-context.xml,设置controller的路径,以及引入数据库配置 <beans xmlns="http://www ...
- 自动生成Mybatis的Mapper文件
自动生成Mybatis的Mapper文件 工作中使用mybatis时我们需要根据数据表字段创建pojo类.mapper文件以及dao类,并且需要配置它们之间的依赖关系,这样的工作很琐碎和重复,myba ...
- 创建mybatis的逆向工程
1.mybatis的逆向工程(我使用的是maven仓库创建) 工作原理:反向工程(通过数据库中的表和字段信息去生成对应的增删改查方法) 其实就是一个自动生成工具 生成实体类(pojo)和映射文件(ma ...
- mybatis 学习视频总结记录
学习mybaits简单增删改查例子记录 此整理是学习视频后的视频内容整理,后半段还没有整理 网易云课堂 SSM高级整合视频 地址 : http://study.163.com/course/cours ...
随机推荐
- Careercup - Microsoft面试题 - 24308662
2014-05-12 07:31 题目链接 原题: I have heard this question many times in microsoft interviews. Given two a ...
- 32、详解Android shape的使用方法(转载)
0.java绘制shape 在官方API介绍中: ShapeDrawable:This object can be defined in an XML file with the <shape& ...
- 项目实战:CRM客户关系管理系统开发
21-CRM第一节内容概要 21.1 Stark组件介绍:实现基本的增删改查+自定义复杂操作: 21.2 单例模式:最简单的单例模式: 21.3 路由系统(分发): 21.4 制作启动文件-Djang ...
- js 遍历对象属性(for in、Object.keys、Object.getOwnProperty) 以及高效地输出 js 数组
js中几种遍历对象的方法,包括for in.Object.keys.Object.getOwnProperty,它们在使用场景方面各有不同. for in 主要用于遍历对象的可枚举属性,包括自有属性. ...
- c#委托使用
public class StepArgs : EventArgs { public int m_IMax = 0; public int m_IStep = 0; public string m_S ...
- C++ bitset类的使用与简介
有些程序要处理二进制位的有序集,每个位可能包含的是0(关)或1(开)的值.位是用来保存一组项或条件的yes/no信息(有时也称标志)的简洁方法.标准库提供了bitset类使得处理位集合更容易一些.要使 ...
- 【转】log4js在PM2的cluster模式下大坑
请直接查看原文:https://blog.yourtion.com/fix-log4js-with-pm2-not-work.html 之前一直使用 debug 还有 console.log 去打日志 ...
- 习题:过路费(kruskal+并查集+LCA)
过路费 [问题描述]在某个遥远的国家里,有 n 个城市.编号为 1,2,3,…,n.这个国家的政府修 建了 m 条双向道路,每条道路连接着两个城市.政府规定从城市 S 到城市 T 需 要收取的过路费 ...
- How to modify a compiled Android application (.apk file)
Today I’d like to share with you my findings about how an existing .apk file can be modified. An .ap ...
- [LOJ#2323]「清华集训 2017」小Y和地铁
[LOJ#2323]「清华集训 2017」小Y和地铁 试题描述 小Y是一个爱好旅行的OIer.一天,她来到了一个新的城市.由于不熟悉那里的交通系统,她选择了坐地铁. 她发现每条地铁线路可以看成平面上的 ...