Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use Mybatis in springboot

Shulou Source: shulou.com Published: 2022-06-01 00:43:02 09月21日 Update

This article focuses on "how to use Mybatis in springboot". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let the editor take you to learn how to use Mybatis in springboot.

Springboot integrated Mybatis

Step one:

Add Mybatis dependency

Org.mybatis.spring.boot mybatis-spring-boot-starter 2.0.0

Step 2:

Add mysql driver

There is no version number because it inherits from the parent project. Of course, you can also specify a version number yourself.

Mysql mysql-connector-java

Generate entity bean, mapping file, DAO interface using reverse engineering provided by Mybatis

Step one:

Create a GeneratorMapper.xml file in the project root directory with the following configuration:

Step two

The configuration in pom.xml is as follows:

Org.mybatis.generator mybatis-generator-maven-plugin 1.3.7 mysql mysql-connector-java 8.0.15 GeneratorMapper.xml true true

Step three

When you double-click the following

There is a hole here. I made a mistake here. The error message is as follows:

Failed to execute goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.7:generate (default-cli) on project sprint_boot_01: Communications link failure

99% is that the connectionURL in the driver and configuration database information is misconfigured, my solution:

DriverClass= "com.mysql.cj.jdbc.Driver" connectionURL= "jdbc:mysql://127.0.0.1:3306/java_pro?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false"

Then double-click to execute, successfully:

The resulting directory is as follows:

At this point, I believe you have a deeper understanding of "how to use Mybatis in springboot". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Configuration version information content engineering files learning generation driver utility deeper success reason interest entity practicality practicality interface simple operation data Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Shulou Tech Info Huawei macOS Xiaomi