Boost Your Java CRUD Speed with MybatisPlusPro: A Complete Guide

This article introduces MybatisPlusPro, an extension of MyBatis‑Plus that automates controller‑level CRUD, pagination, dynamic queries, data auditing, permission control, and performance optimizations, showing how developers can dramatically reduce code and improve efficiency in Java backend projects.

Java Tech Enthusiast
Java Tech Enthusiast
Java Tech Enthusiast
Boost Your Java CRUD Speed with MybatisPlusPro: A Complete Guide

MybatisPlusPro is an extension of MyBatis‑Plus that adds a layer of generic CRUD functionality to the Controller layer, allowing developers to inherit BaseController and automatically obtain RESTful create, read, update, delete, pagination, sorting, and statistics endpoints.

Core Features

One‑line CRUD: BaseController provides standard REST endpoints such as /insert, /deleteById, /updateById, /getById, and /save, eliminating repetitive code.

@RestController
@RequestMapping("/blog")
public class BlogController extends BaseController<Blog, BlogService> {
    // No additional code needed
}

Pagination: MybatisPlusPro automatically processes pagination parameters and supports dynamic sorting.

@PostMapping("/page")
public ResponseUtils page(@RequestBody PageParamDto<Blog> pageParamDto) {
    Page<Blog> page = new Page<>(pageParamDto.getPage(), pageParamDto.getSize());
    QueryWrapper<Blog> queryWrapper = new QueryWrapper<>();
    if (!StrUtil.isEmpty(pageParamDto.getAsc())) {
        queryWrapper.orderByAsc(pageParamDto.getAsc().split(","));
    }
    if (!StrUtil.isEmpty(pageParamDto.getDesc())) {
        queryWrapper.orderByDesc(pageParamDto.getDesc().split(","));
    }
    return ResponseUtils.success(baseService.page(page, queryWrapper));
}

Dynamic query: By passing an entity object, MybatisPlusPro builds a WHERE clause via reflection.

@PostMapping("/list")
public ResponseUtils list(@RequestBody Blog blog) {
    QueryWrapper<Blog> queryWrapper = ApprenticeUtil.getQueryWrapper(blog);
    return ResponseUtils.success(baseService.list(queryWrapper));
}

Advanced Features

Data audit: Mybatis‑Mate can compare old and new objects and output differences.

// Asynchronous callback
applicationEventPublisher.publishEvent(new DataAuditEvent(t -> {
    List<Change> changes = t.apply(newVersion, oldVersion);
    changes.forEach(change -> {
        ValueChange vc = (ValueChange) change;
        System.err.println(String.format("%s mismatch, expected %s, actual %s",
            vc.getPropertyName(), vc.getLeft(), vc.getRight()));
    });
}));
// Manual call
DataAuditor.compare(obj1, obj2);

Data permission: @DataScope annotation adds row‑level access control automatically.

@DataScope(type = "test", value = {
    @DataColumn(alias = "u", name = "department_id"),
    @DataColumn(alias = "u", name = "mobile")
})
@Select("select u.* from user u")
List<User> selectTestList(IPage<User> page, Long id, @Param("name") String username);

Table structure maintenance: Mybatis‑Mate can generate DDL scripts and maintain version history automatically.

@Component
public class MysqlDdl implements IDdl {
    @Override
    public List<String> getSqlFiles() {
        return Arrays.asList("db/tag-schema.sql", "D:\\db\\tag-data.sql");
    }
}

Performance Optimizations

Batch insert: Enable rewriteBatchedStatements and use saveBatch to insert thousands of rows in seconds.

jdbc:mysql://localhost:3306/db_name?rewriteBatchedStatements=true
long examId = zzidc.nextId();
exam.setId(examId);
examMapper.insert(exam);
// Build question and option lists, then
questionService.saveBatch(questionList, BATCH_SIZE);
optionService.saveBatch(optionList, BATCH_SIZE);

Pagination optimization: Use count(1) and ensure sorting fields have indexes.

queryWrapper.select("count(1) as total");

Optimistic lock: Add @Version field and configure MybatisPlusInterceptor.

@Version
private Integer version;

@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
    MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
    interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
    return interceptor;
}

Version 3.5.12 (2025) Highlights

Snowflake ID configuration with manual or automatic workerId/datacenterId.

Enhanced batch operations with List return values.

Logical delete now supports automatic fill.

SQL injection protection via UpdateWrapper.checkSqlInjection.

In comparison with plain MyBatis‑Plus, MybatisPlusPro reduces code volume, provides built‑in controller CRUD, automatic pagination, batch enhancements, data‑scope annotation, and table‑structure maintenance, making it a versatile “Swiss‑army‑knife” for Java backend development.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

MyBatisCRUDData Auditing
Java Tech Enthusiast
Written by

Java Tech Enthusiast

Sharing computer programming language knowledge, focusing on Java fundamentals, data structures, related tools, Spring Cloud, IntelliJ IDEA... Book giveaways, red‑packet rewards and other perks await!

0 followers
Reader feedback

How this landed with the community

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.