Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Mybatis in springboot

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report