/images/logo.jpg

[Github] 3. Basic-Check: Validation Framework

Introduction

Parameter validation is a common and crucial requirement in daily Java development. Traditional parameter validation typically requires writing extensive if-else conditional code in each method, which is not only redundant and tedious but also prone to omissions. Basic-Check-Java was born to solve this pain point as a lightweight parameter validation framework.

This article will provide an in-depth introduction to Basic-Check-Java’s design philosophy, core features, and practical applications, helping developers quickly master this practical tool.

[Cluster] 1. RAFT Algorithm: A Complete Evolution from Single Node to Distributed Consensus

Introduction

  • RAFT (Raft Consensus Algorithm) is a distributed consensus algorithm designed to solve the problem of achieving data state agreement among multiple nodes in distributed systems.
  • Compared to the renowned Paxos algorithm, RAFT’s design philosophy emphasizes “understandability” through clear role separation and straightforward state transitions, making it easier for developers to comprehend and implement.
  • This article demonstrates the complete evolution of the RAFT algorithm from single-node to multi-node clusters through 11 detailed diagrams, covering key scenarios including normal operation, failure handling, network partitions, and conflict resolution.

Core RAFT Concepts

  • Before diving into the analysis, let’s familiarize ourselves with several core concepts of RAFT:

Node States:

[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

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

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

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’