Step-by-Step Guide to Using MybatisX with Spring Boot for Rapid Backend Development
This tutorial explains what MybatisX is, outlines its advantages, and provides a detailed, code‑rich walkthrough for integrating the plugin into a Spring Boot project, configuring the database, generating MyBatis‑Plus entities, and writing a simple controller to query data.
What is MybatisX? MybatisX is an IntelliJ IDEA plugin that streamlines repetitive tasks when working with MyBatis and MyBatis‑Plus, accelerating backend development.
Benefits of using MybatisX
Saves a large amount of persistence‑layer coding time.
Offers powerful features that support various business needs.
Simple configuration eliminates the need for complex XML files.
How to use MybatisX
1. Create a simple database.
2. Create a basic Spring Boot project.
3. Add the MyBatis‑Plus starter dependency to <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.5.1</version> </dependency> in pom.xml .
4. Install the MybatisX plugin via File → Settings → Plugins .
5. Open the Database tool window (press SHIFT twice) and add a MySQL connection, ensuring the server timezone is set to GMT to avoid connection errors.
6. After a successful connection, the database schema and tables become visible.
7. Right‑click a table and select MybatisX‑Generator to configure prefix/suffix removal, output directories, and other options.
8. In the generator wizard, enable the latest MyBatis‑Plus version and Lombok for simplified code.
9. Finish the wizard; MybatisX automatically generates the entity class, Mapper, Service, and corresponding interfaces for the selected table.
Database configuration (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: passwordController example 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 application and accessing /test returns the user record, confirming that MybatisX integration with Spring Boot is complete.
Sohu Tech Products
A knowledge-sharing platform for Sohu's technology products. As a leading Chinese internet brand with media, video, search, and gaming services and over 700 million users, Sohu continuously drives tech innovation and practice. We’ll share practical insights and tech news here.
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.