Integrating MybatisX Plugin with Spring Boot for Rapid MyBatis Development
This tutorial walks through setting up a simple Spring Boot project, adding MyBatis‑Plus dependencies, configuring MybatisX in IntelliJ IDEA, generating entity, mapper, service, and controller code, and handling common connection issues, providing a complete end‑to‑end example of rapid MyBatis development.
Hello everyone, I'm Chen.
MybatisX is an IntelliJ IDEA plugin that streamlines repetitive MyBatis and MyBatis‑Plus tasks, boosting development speed.
Benefits of Using MybatisX
Significant reduction in persistence‑layer code development time.
Powerful features that support various business development needs.
Simple configuration, eliminating complex XML/annotation files.
How to Use MybatisX
1. Create a simple database.
2. Create a simple Spring Boot project.
3. Add MyBatis‑Plus dependency in pom.xml :
<!--mybatisPlus-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.1</version>
</dependency>4. Install MybatisX plugin via File → Settings → Plugins .
5. Press Shift twice and search "database" to open the database tool window.
6. Create a new MySQL connection.
Enter username, password, and database name.
If the Test Connection fails, set the server timezone to GMT (Greenwich Mean Time) in the Advanced settings.
After fixing the timezone, the connection succeeds.
You can now see the database schema and tables.
Right‑click a table to access MybatisX‑Generator .
In the generator UI you can configure prefix/suffix removal, output directories, etc.
On the next page, select the latest Mybatis‑Plus version (3.x) and enable Lombok for simplified code.
After clicking Finish , MybatisX generates the entity class, mapper XML, service, and controller for the selected table.
Configure the datasource in application.yaml :
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/user?characterEncoding=utf-8&useSSL=false&serverTimezone=GMT
username: root
password: passwordExample controller using MyBatis‑Plus query wrapper:
package com.example.mybatixtest.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.mybatixtest.pojo.User;
import com.example.mybatixtest.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class TestController {
@Autowired
UserService userService;
@GetMapping("/test")
public User test() {
QueryWrapper
userQueryWrapper = new QueryWrapper<>();
userQueryWrapper.eq("user_id", 1);
User user = userService.getOne(userQueryWrapper);
return user;
}
}Running the endpoint returns the expected user data.
Thus the integration of MybatisX with Spring Boot is complete.
Final Note (Support the Author)
If this guide helped you, please like, view, share, and bookmark the article. Your support motivates me to keep creating content.
Additionally, I run a knowledge community where you can access premium Spring, MyBatis, DDD micro‑service, and large‑scale data sharding tutorials for a small fee.
Follow the public account "Code Monkey Technical Column" for more resources and join the discussion group by replying "join group".
Code Ape Tech Column
Former Ant Group P8 engineer, pure technologist, sharing full‑stack Java, job interview and career advice through a column. Site: java-family.cn
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.