Bugs encountered when using mybatis-generator with mysql8.0.3 in IDEA

Bugs encountered when using mybatis-generator with mysql8.0.3 in IDEA

1. Add the plug-in and add the following configuration under the pom file

<!-- mybatis-generator -->
  <plugin>
  <groupId>org.mybatis.generator</groupId>
  <artifactId>mybatis-generator-maven-plugin</artifactId>
  <version>1.3.5</version>
  <configuration>
   <configurationFile>
   <!--Here is the path to configure generatorConfig.xml. If it is not specified, the generatorConfig.xml file will be found in the resources directory by default. -->
   </configurationFile>
   <verbose>true</verbose>
   <overwrite>true</overwrite>
  </configuration>
  <dependencies>
   <dependency>
   <groupId>mysql</groupId>
   <artifactId>mysql-connector-java</artifactId>
   <version>8.0.11</version>
   </dependency>
  </dependencies>
  </plugin>

2. Create generatorConfig.xml under resources with the following content:

<?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 is the main configuration information for reverse engineering -->
 <!-- id: give it a name-->
 <!-- targetRuntime: Set the generated file to apply to that mybatis version -->
 <context id="default" targetRuntime="MyBatis3">
 <!--optional, refers to controlling comments when creating a class-->
 <commentGenerator>
  <property name="suppressDate" value="true"/>
  <!-- Whether to remove automatically generated comments true: yes: false: no -->
  <property name="suppressAllComments" value="true"/>
 </commentGenerator>
 <!--jdbc database connection wg_insert is the database name-->
 <jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
   connectionURL="jdbc:mysql://localhost:3306/wg_insert?useUnicode=true&amp;characeterEncoding=utf-8&amp;serverTimezone=UTC" userId="root"
   password="123456"></jdbcConnection>
 <!--Optional, type processor, conversion control between database type and java type-->
 <javaTypeResolver>
  <!-- By default, the decimal and bigInt in the database correspond to the BigDecimal class in sql in Java -->
  <!-- Not double or long type -->
  <!-- Use common basic types instead of reference types under the sql package-->
  <property name="forceBigDecimals" value="false"/>
 </javaTypeResolver>
 <!-- targetPackage: the package where the generated entity class is located -->
 <!-- targetProject: the hard disk location where the generated entity class is located -->
 <javaModelGenerator targetPackage="com.wglvzyx.mybatisredis.entity"
    targetProject="src/main/java">
  <!-- Whether to allow sub-packages -->
  <property name="enableSubPackages" value="false"/>
  <!-- Whether to add a constructor to modal-->
  <property name="constructorBased" value="true"/>
  <!-- Whether to clean up the blank characters on both sides of the string queried from the database -->
  <property name="trimStrings" value="true"/>
  <!-- Establish whether the modal object is immutable, that is, the generated modal object will not have a setter method, only a constructor -->
  <property name="immutable" value="false"/>
 </javaModelGenerator>
 <!-- targetPackage and targetProject: the package and location of the generated mapper file -->
 <sqlMapGenerator targetPackage="mapper"
    targetProject="src/main/resources">
  <!-- For a database configuration, whether to use schema as a subpackage name -->
  <property name="enableSubPackages" value="false"/>
 </sqlMapGenerator>
 <!-- targetPackage and targetProject: the package and location of the generated interface file -->
 <javaClientGenerator type="XMLMAPPER"
    targetPackage="com.wglvzyx.mybatisredis.dao" targetProject="src/main/java">
  <!-- For a configuration of Oracle database, whether to use schema as a subpackage name -->
  <property name="enableSubPackages" value="false"/>
 </javaClientGenerator>
 <!-- tableName is the table name in the database, domainObjectName is the generated JAVA model name, the following parameters do not need to be changed, if you want to generate more tables, continue to add table tags below-->
 <table tableName="student" domainObjectName="Student"
  enableCountByExample="false" enableUpdateByExample="false"
  enableDeleteByExample="false" enableSelectByExample="false"
  selectByExampleQueryId="false"></table>
 </context>
</generatorConfiguration>

3. Run, there are two methods:

Method 1:

Add a "Run" option in Intellij IDEA and use Maven to run the mybatis-generator-maven-plugin plug-in (mybatis-generator:generate -e):

insert image description here

Method 2:

Open the Maven panel on the right, open mybatis-generator:generate under Mybatis-generator under Plugins, right-click Run Maven Build!

insert image description here

Notice:

Because I use mysql-8.0.11

So the configuration is different

The main thing is that the new version has new features. First of all, the latest official support is to change com.mysql.jdbc.Driver to com.mysql.cj.jdbc.Driver. In addition, mysql8.0 does not need to establish an SSL connection. You need to explicitly turn it off, that is, useSSL=false in the url; finally, you need to set CST, which can be regarded as the standard time of the United States, Australia, Cuba or China. serverTimezone is used to set the time zone. You can check the relevant information to find out more!

jdbc.driverClassName=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/mytest?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&useSSL=false&serverTimezone=UTC
jdbc.username=root
jdbc.password=123456

This is the end of this article about the pitfalls of using mybatis-generator with IDEA and MySQL 8.0.3. For more information about using mybatis-generator with MySQL in IDEA, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • MySQL 8.0.24 version installation and configuration method graphic tutorial
  • Some improvements in MySQL 8.0.24 Release Note
  • Implementation of MySQL's MVCC multi-version concurrency control
  • The best solution for resetting the root password of MySQL 8.0.23
  • About the configuration problem of MyBatis connecting to MySql8.0 version
  • How to solve the problem that Seata cannot use MySQL 8 version
  • Detailed explanation of DBeaver connecting to MySQL version 8 and above and solving possible problems
  • Solution to the garbled code problem in MySQL 5.x
  • Detailed tutorial on installing MySQL 8.0.20 database on CentOS 7
  • Solution to ONLY_FULL_GROUP_BY error in Mysql5.7 and above
  • Solve the installation problem of mysql8.0.19 winx64 version
  • Django 2.2 and PyMySQL version compatibility issues
  • Steps to install MySQL 5.7 in binary mode and optimize the system under Linux
  • Installation of various versions of MySQL 8.0.18 and problems encountered during installation (essence summary)
  • Super detailed teaching on how to upgrade the version of MySQL

<<:  Javascript common higher-order functions details

>>:  In-depth understanding of Vue's plug-in mechanism and installation details

Recommend

How to use Docker to limit container resources

Problem Peeping In the server, assuming that the ...

Chinese website user experience rankings

<br />User experience is increasingly valued...

Commands to find domain IP address in Linux terminal (five methods)

This tutorial explains how to verify the IP addre...

Detailed explanation of the functions and usage of MySQL common storage engines

This article uses examples to illustrate the func...

Specific use of GNU Parallel

what is it? GNU Parallel is a shell tool for exec...

Implement a simple search engine based on MySQL

Table of contents Implementing a search engine ba...

A detailed introduction to seata docker high availability deployment

Version 1.4.2 Official Documentation dockerhub st...

Vue uses GraphVis to develop an infinitely expanded relationship graph

1. Go to the GraphVis official website to downloa...

Use of kubernetes YAML files

Table of contents 01 Introduction to YAML files Y...

MySQL index cardinality concept and usage examples

This article uses examples to explain the concept...

MySQL Basic Tutorial: Detailed Explanation of DML Statements

Table of contents DML statements 1. Insert record...

How to view the network routing table in Ubuntu

What are Routing and Routing Table in Linux? The ...

Three ways to achieve background blur in CSS3 (summary)

1. Normal background blur Code: <Style> htm...

Based on JavaScript ES new features let and const keywords

Table of contents 1. let keyword 1.1 Basic Usage ...