/images/logo.jpg

[Github] 2. MyBatis Generator Custom Plugins

[Github] 2. MyBatis Generator Custom Plugins

🔗 Project Repository: mybatis-generator-custome-plugins

A powerful collection of MyBatis Generator custom plugins designed to enhance code generation capabilities with MySQL-specific features, DTO layer generation, and automatic Service layer generation.

🚀 Features Overview

This plugin collection includes 6 custom plugins:

Plugin NameDescriptionKey Features
InsertIgnoreIntoPluginMySQL INSERT IGNORE statement supportBatch insert ignoring duplicate records
InsertOnDuplicateKeyPluginMySQL ON DUPLICATE KEY UPDATE supportAuto update on insert conflicts
ReplaceIntoPluginMySQL REPLACE INTO statement supportReplace insert operations
DtoGeneratorPluginDTO layer code generationLombok annotations, Entity conversion methods
ServiceGeneratorPluginService layer code generationInterface + Implementation, Complete CRUD operations
CustomerMapperPluginCustom Mapper generationExtended native Mapper functionality

📦 Dependency Analysis

Core Dependencies

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
<!-- MyBatis Generator Core Dependency -->
<dependency>
  <groupId>org.mybatis.generator</groupId>
  <artifactId>mybatis-generator-core</artifactId>
  <version>1.4.2</version>
</dependency>

        <!-- MyBatis Dynamic SQL Support -->
<dependency>
<groupId>org.mybatis.dynamic-sql</groupId>
<artifactId>mybatis-dynamic-sql</artifactId>
<version>1.5.2</version>
</dependency>

        <!-- MyBatis Spring Boot Integration -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>3.0.5</version>
</dependency>

Maven Plugin Configuration

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17

<plugin>
  <groupId>org.mybatis.generator</groupId>
  <artifactId>mybatis-generator-maven-plugin</artifactId>
  <version>1.4.2</version>
  <configuration>
    <verbose>true</verbose>
    <overwrite>true</overwrite>
  </configuration>
  <dependencies>
    <dependency>
      <groupId>com.goody.utils</groupId>
      <artifactId>mybatis-generator-custome-plugins</artifactId>
      <version>1.0.0</version>
    </dependency>
  </dependencies>
</plugin>

🔧 Plugin Details

MySQL Extension Plugins

InsertIgnoreIntoPlugin

  • Function: Adds INSERT IGNORE statement support to Mapper
  • Generated Methods: insertIgnoreCustom(), insertIgnoreBatchCustom()
  • Use Cases: Ignore primary key conflicts during batch inserts

InsertOnDuplicateKeyPlugin

  • Function: Adds ON DUPLICATE KEY UPDATE statement support to Mapper
  • Generated Methods: insertOnDuplicateKeyCustom(), insertOnDuplicateKeyBatchCustom()
  • Use Cases: Auto update records on duplicate key conflicts during insert

ReplaceIntoPlugin

  • Function: Adds REPLACE INTO statement support to Mapper
  • Generated Methods: replaceIntoCustom(), replaceIntoBatchCustom()
  • Use Cases: Replace existing records or insert new ones

DTO Layer Generation Plugin

DtoGeneratorPlugin

  • Function: Automatically generates DTO classes
  • Features:
    • Lombok annotation support (@Data, @Builder, @AllArgsConstructor, @NoArgsConstructor)
    • Auto-generated fromEntity() and toEntity() conversion methods
    • Package structure: *.model.dto

Service Layer Generation Plugin

ServiceGeneratorPlugin

  • Function: Automatically generates Service interfaces and implementation classes
  • Features:
    • Complete CRUD operation methods
    • Support for single and composite primary keys
    • Spring annotation support (@Service, @Autowired)
    • Package structure: *.service.interfaces and *.service.impl

Custom Mapper Plugin

CustomerMapperPlugin

  • Function: Generates extended Mapper interfaces
  • Package structure: *.dao.customer

💻 Usage Guide

Step 1: Add Dependencies

Add the plugin to your project:

[Customs] 1. IntelliJ IDEA Configuration & Recommended Plugins

[Customs] 1. IntelliJ IDEA Configuration & Recommended Plugins

Introduction

As one of the most powerful Java IDEs available, IntelliJ IDEA can be significantly enhanced through proper configuration and carefully selected plugins. This guide presents a curated collection of essential plugins and configuration skills that will transform your development experience.

The goal is to provide ready-to-use configurations and plugins that immediately improve productivity, code quality, and development workflow.

Essential Plugins

🔧 Development Tools

CamelCase (3.0.12)

/images/7.%20customs%20-%20idea/plugin/CamelCase%20(3.0.12).png

[Java] 2. Unit Test Basic Usage

[Java] 2. Unit Test Basic Usage

Mockito Basic Usage

In unit testing, many tests (except Util classes) need to mock some services to ensure only the current logic being tested is actually tested.

Specifically, you need to first mock an object, then mock the methods of this object, and then you can use the mocked methods to test the logic you want to test.

Mock Objects

First, you need to declare the interfaces/implementation classes that need to be mocked in the Test class. For example:

[Spring] 1. Spring Web CompletionStage Overview

[Spring] 1. Spring Web CompletionStage Overview

Introduction

  • Spring-web provides excellent support for asynchronous operations, which can be used for many optimizations through asynchronous return forms:
    • Improve throughput
    • Fine-tune execution thread pools for various business operations

Sample Code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
 * async interface controller
 *
 * @author Goody
 * @version 1.0, 2024/9/19
 */
@RestController
@RequestMapping("/goody")
@RequiredArgsConstructor
@Slf4j
public class GoodyAsyncController {

    private static final AtomicInteger COUNT = new AtomicInteger(0);
    private static final Executor EXECUTOR = new ThreadPoolExecutor(
        10,
        10,
        10,
        TimeUnit.SECONDS,
        new ArrayBlockingQueue<>(10),
        r -> new Thread(r, String.format("customer-t-%s", COUNT.addAndGet(1)))
    );

    @GetMapping("async/query1")
    public CompletionStage<String> asyncQuery1() {
        log.info("async query start");
        return CompletableFuture.supplyAsync(() -> {
            log.info("async query sleep start");
            ThreadUtils.sleep(1000);
            log.info("async query sleep done");
            log.info("async query done");
            return "done";
        }, EXECUTOR);
    }

    @GetMapping("sync/query1")
    public String syncQuery1() throws InterruptedException {
        log.info("sync query start");
        final CountDownLatch latch = new CountDownLatch(1);
        EXECUTOR.execute(() -> {
            log.info("sync query sleep start");
            ThreadUtils.sleep(1000);
            log.info("sync query sleep done");
            latch.countDown();
        });
        latch.await();
        log.info("sync query done");
        return "done";
    }
}
  • Defined a custom thread pool for use in asynchronous scenarios
  • Here’s one synchronous and one asynchronous endpoint, let’s look at the specific request scenarios

Single Request

Request Async Interface

curl –location ‘127.0.0.1:50012/goody/async/query1’

[Java] 1. Lombok

[Java] 1. Lombok

Introduction

  • Lombok is a Java library that can automatically generate repetitive code for Java classes, such as getter, setter, equals, and hashCode methods.

Principles

  • Lombok’s working principle is based on Annotation Processors and the Java Compiler API.

  • When Lombok is discovered by the compiler, it uses annotation processors to modify Java code. During this process, Lombok checks for specific annotations in classes and generates corresponding code based on these annotations, such as getter and setter methods.

[MySQL] 1. MySQL Fast Query Insights

[MySQL] 1. MySQL Fast Query Insights

Preface

  • Let’s start with some of the most common optimization measures we use in daily learning and business scenarios

    1. Do more things in the same unit of time

      • QuickSort uses the binary search idea to sort multiple arrays within a single loop

        /images/3.%20%E6%B5%85%E8%B0%88MySQL%E5%BF%AB%E9%80%9F%E6%9F%A5%E8%AF%A2/1.%20%E5%BF%AB%E6%8E%92.jpg

    2. Query less information in total

      • KMP algorithm preprocesses the main string to reduce the number of matches. This is the power of logic