Backend Development 5 min read

Step-by-Step Guide to Using MybatisX with Spring Boot

This article introduces MybatisX, an IntelliJ IDEA plugin that streamlines MyBatis and MyBatis‑Plus development, and provides a detailed step‑by‑step tutorial on setting up a Spring Boot project, configuring the database, generating code, and writing a simple controller using MyBatis‑Plus.

Selected Java Interview Questions
Selected Java Interview Questions
Selected Java Interview Questions
Step-by-Step Guide to Using MybatisX with Spring Boot

MybatisX is an IntelliJ IDEA plugin that simplifies repetitive tasks when using MyBatis and MyBatis‑Plus, accelerating backend development.

Benefits of Using MybatisX

Significant reduction in persistence layer code development time.

Powerful features that support various business needs.

Simple configuration, eliminating 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 pom.xml :

com.baomidou
mybatis-plus-boot-starter
3.5.1

4. Install the MybatisX plugin via IDE Settings → Plugins.

5. Open the Database tool window (Shift+Shift) and add a MySQL connection.

6. Configure connection details (user, password, database name). If the test connection fails due to timezone, set serverTimezone to GMT in the Advanced settings.

After a successful connection, the database schema and tables become visible. Right‑click a table and select MybatisX‑Generator to open the generation wizard.

In the wizard, configure prefix/suffix removal, output directory, and select the latest MyBatis‑Plus version (3.x) along with Lombok for simplified code.

Finish the wizard; MybatisX automatically generates the entity class, Mapper, Service, and corresponding interfaces 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: password

Example 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;
    }
}

Accessing /test returns the user data, confirming that MybatisX integration with Spring Boot is complete.

backendJavaSpringBootMyBatis-PlusTutorialMyBatisX
Selected Java Interview Questions
Written by

Selected Java Interview Questions

A professional Java tech channel sharing common knowledge to help developers fill gaps. Follow us!

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.