最近试了一下mysql8的逆向工程工具

1.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE generatorConfiguration PUBLIC
"-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"../mybatis-generate-core/src/main/resources/org/mybatis/generator/config/xml/mybatis-generator-config_1_0.dtd"> <generatorConfiguration> <context id="myTable"> <property name="javaFileEncoding" value="UTF-8"/> <!--哪个依赖合适用哪个-->
<!-- <plugin type="org.mybatis.generator.plugins.UserDefinePlugin"/>-->
<plugin type="org.mybatis.generator.plugins.SerializablePlugin"></plugin>
<jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/baidu?characterEncoding=UTF-8&amp;autoReconnect=true&amp;serverTimezone=GMT%2B8&amp;useSSL=false"
userId="root"
password="123456">
<property name="remarksReporting" value="true"/>
</jdbcConnection>
<javaTypeResolver>
<property name="forceBigDecimals" value="false"/>
<property name="yp_dateTime2String" value="true"/>
<property name="yp_projectName" value="prs"/>
</javaTypeResolver>
<!-- domain实体 -->
<!--D:\code\haiyu\src\main\java\com\haiyu\manager\pojo-->
<javaModelGenerator targetPackage="com.baidu.entity"
targetProject="D:/myBatisGenerator/src/main/java">
<!--<property name="rootClass" value="com.yp.custtrack.domain.BaseDomain"/>-->
</javaModelGenerator>
<!-- xml映射文件 -->
<!--D:\code\haiyu\src\main\resources\mapper-->
<sqlMapGenerator targetPackage="mapper"
targetProject="D:/myBatisGenerator/src/main/resources">
</sqlMapGenerator>
<!-- dao 接口 -->
<!--D:\code\haiyu\src\main\java\com\haiyu\manager\dao-->
<javaClientGenerator targetPackage="com.baidu.dao"
targetProject="D:/myBatisGenerator/src/main/java"
type="XMLMAPPER">
<!--是否允许建立子包(对应MySql的scheme)-->
<property name="enableSubPackages" value="true"/>
</javaClientGenerator>
<table tableName="sys_user" domainObjectName="SysUser"/> </context>
</generatorConfiguration>

主要点: 使用 com.mysql.cj.jdbc.Driver驱动

2.pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <groupId>com.myBatisGenerator</groupId>
<artifactId>myBatisGenerator</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.13</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.0</version>
</dependency>
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.4</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.0.10.RELEASE</version>
</dependency> </dependencies> </project>

主要点: 使用 mysql-connector-java 的jar包要用8的版本

3.Test

package com.baidu;

import org.junit.Test;
import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.exception.InvalidConfigurationException;
import org.mybatis.generator.internal.DefaultShellCallback; import java.util.ArrayList;
import java.util.List; public class MyBatisGeneratorTest { @Test
public void doGenerate() throws Exception {
List<String> warnings = new ArrayList<String>();
ConfigurationParser cp = new ConfigurationParser(warnings);
//Configuration config = cp.parseConfiguration(this.getClass().getClassLoader().getResourceAsStream("generatorConfig_for_oracle(wmsserv).xml"));
//String xmlName="generatorConfig.xml";
String xmlName = "generatorConfig_mysql8.xml"; //mysql 8
Configuration config = cp.parseConfiguration(this.getClass().getClassLoader().getResourceAsStream(xmlName)); DefaultShellCallback shellCallback = new DefaultShellCallback(true); try {
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, shellCallback, warnings);
myBatisGenerator.generate(null);
System.out.println("逆向工程生成数据成功!!!"); } catch (InvalidConfigurationException e) {
//失败
}
} }

4.效果 (mapper接口的@Repository注解或@Mapper注解可以手动添加一下)

5.GitHub传送门

https://github.com/ColoZhu/myBatisGenerator.git

Mysql8+mybatisGenerator (mysql 8的逆向工程)的更多相关文章

  1. PowerDesigner连接MySQL,建立逆向工程图解

    传说中,程序员们喜欢用powerDesign进行数据库建模.通常都是先设计出物理模型图,在转换出数据库需要的SQL语句,从而生成数据库.但,江湖中流传着"powerDesign逆向工程&qu ...

  2. 使用powerdesigner连接MySQL并设置逆向工程图文教程

    我用的是Win7 x64的系统,安装了64为的mysql-connector-odbc-5.1.10-winx64.msi在数据源中test正常,但在powerdesigner连接Mysql总是弹出“ ...

  3. 第三章 mybatis-generator + mysql/ptsql

    用了mybatis-generator,我就不再想用注解了,这与我之前说的注解与XML并用是矛盾的,知识嘛,本来就是多元化的,今天喜欢这个,明天喜欢那个,哈哈,看了mybatis-generator下 ...

  4. mybatis-generator + mysql/ptsql

    用了mybatis-generator,我就不再想用注解了,这与我之前说的注解与XML并用是矛盾的,知识嘛,本来就是多元化的,今天喜欢这个,明天喜欢那个,哈哈,看了mybatis-generator下 ...

  5. CentOS7快速配置nginx node mysql8.0

    目录: (一)基础准备 (二)安装node (三)安装nginx (四)安装mySql8.0 (五)整体配置 (六)安装PM2守护进程 (一)基础准备1.1 概述 服务器操作系统为 centos7.4 ...

  6. Centos7服务器中安装MySQL(选择一个你想要的版本)

    开始,我默认安装了MySQL8,但是在测试的时候发现通过Hibernate连接之前的MySQL5.7的代码运行在连接新版本的库的时候发生异常,出于时间原因没有深度排查 但是我严重怀疑是版本匹配问题,为 ...

  7. MySQL 8.0 Docker使用注解

    PUBLIC | AUTOMATED BUILD cytopia/mysql-8.0 Last pushed: 8 months ago Repo Info Tags Dockerfile Build ...

  8. mysql 编译安装 window篇

    传送门 # mysql下载地址 https://www.mysql.com/downloads/ # 找到MySQL Community Edition (GPL) https://dev.mysql ...

  9. Mac安装mysql8.0.12

    ···shell 下载 wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.12-macos10.13-x86_64.tar.gz ...

随机推荐

  1. excel导入、下载功能

    1.excel导入.下载功能 2.首先,我们是居于maven项目进行开发引入poi,如果不是那就手动下载相应的jar包引入项目就可以了 <!-- poi --> <dependenc ...

  2. ZJOI 2006 物流运输 bzoj1003

    题目描述 物流公司要把一批货物从码头A运到码头B.由于货物量比较大,需要n天才能运完.货物运输过程中一般要转停好几个码头.物流公司通常会设计一条固定的运输路线,以便对整个运输过程实施严格的管理和跟踪. ...

  3. NOI2016

    luoguP1712 [NOI2016]区间 这是一道送分题. 对于我这种每天抄题解不动脑子思维僵化得厉害的智障选手就是送命题. 一直在想端点排序各种Treap搞... 正解: 已知一些区间,如何判断 ...

  4. [TJOI 2018]游园会

    题意:求NOI的合法串... 思路: 首先这个似乎和后缀自动机没关系(话说TJ不考后缀自动机??),其实就是一个\(DP\)套\(DP\),考虑如果不看兑奖串就是一个LCS,当出现时多记一维即可. # ...

  5. FTP Active & Passive

          在主动模式下,FTP客户端随机开启一个大于1024的端口N向服务器的21号端口发起连接,然后开放N+1号端口进行监听,并向服务器发出PORT N+1命令.服务器接收到命令后,会用其本地的F ...

  6. LightOJ-1259-Goldbach`s Conjecture-素数打表+判断素数对数

    Goldbach's conjecture is one of the oldest unsolved problems in number theory and in all of mathemat ...

  7. PAT甲级——A1116 Come on! Let's C

    "Let's C" is a popular and fun programming contest hosted by the College of Computer Scien ...

  8. Windows与Linux获取进程集合的方法

    Windows: List<String> tasklist=new ArrayList<String>(); try { Process process = Runtime. ...

  9. wangEditor 菜单栏随页面滚动位置改变(吸顶)问题解决

    参考:https://www.kancloud.cn/wangfupeng/wangeditor2/113980 当页面向下滚动到隐藏了菜单栏时,编辑器默认会fixed菜单栏,即让菜单栏保持『吸顶』状 ...

  10. 2018-9-20-在-Windows-下那些好用的调试软件

    title author date CreateTime categories 在 Windows 下那些好用的调试软件 lindexi 2018-9-20 17:37:1 +0800 2018-09 ...