Backend Development 7 min read

Unlock Enterprise‑Level Data Handling with MyBatis‑Mate 1.0.1: Features & Code Guide

The release of MyBatis‑Mate 1.0.1 introduces enterprise‑grade features such as dictionary binding, field encryption, data desensitization, automatic DDL maintenance, and dynamic multi‑datasource sharding, accompanied by code examples, future roadmap, and Maven dependencies for seamless integration into Spring Boot projects.

Java Architecture Diary
Java Architecture Diary
Java Architecture Diary
Unlock Enterprise‑Level Data Handling with MyBatis‑Mate 1.0.1: Features & Code Guide

mybatis-plus Enterprise edition mybats-mate 1.0.1 is released.

This module targets enterprise‑level data agile and elegant processing, using annotations and design patterns to simplify complex data handling logic and encapsulate it at the framework level, freeing developers.

Current version main features

Dictionary binding

Field encryption

Data desensitization

Dynamic DDL structure maintenance

Multi‑datasource sharding (database and table partitioning)

Future plans

Data audit records

Elegant multi‑table handling solution

More powerful visual code generator module

Other features (feedback welcomed)

Dictionary binding example

<code>@FieldDict(type = "user_sex", target = "sexText")
private Integer sex;
private String sexText;</code>

Implementation of IDataDict provides the dictionary data source and is injected into the Spring container.

<code>@Component
public class DataDict implements IDataDict {
    private Map<String, String> SEX_MAP = new ConcurrentHashMap<String, String>() {{
        put("0", "女");
        put("1", "男");
    }};
    @Override
    public String getNameByCode(FieldDict fieldDict, String code) {
        System.err.println("字段类型:" + fieldDict.type() + ",编码:" + code);
        return SEX_MAP.get(code);
    }
}</code>

Field encryption example

<code>@FieldEncrypt(algorithm = Algorithm.PBEWithMD5AndDES)
private String password;</code>

The @FieldEncrypt annotation encrypts the stored value and automatically decrypts it on query, supporting global configuration of encryption algorithms and custom IEncryptor implementations.

Data desensitization example

<code>@FieldSensitive(type = "testStrategy")
private String username;
@FieldSensitive(type = SensitiveType.mobile)
private String mobile;</code>

Built‑in SensitiveType provides nine common strategies (e.g., Chinese name, bank card, mobile number, email, ID card, etc.). Custom strategies can be added via a Spring @Configuration bean.

<code>@Configuration
public class SensitiveStrategyConfig {
    @Bean
    public ISensitiveStrategy sensitiveStrategy() {
        return new SensitiveStrategy().addStrategy("testStrategy", t -> t + "***test***");
    }
}</code>

DDL automatic maintenance example

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

Supports MySQL and PostgreSQL; other databases can be added upon request.

Dynamic multi‑datasource sharding example

<code>ddlScript.run(new StringReader("DELETE FROM user;\nINSERT INTO user (id, username, password, sex, email) VALUES (20, 'Duo', '123456', 0, '[email protected]');"));</code>

Sharding supports free switching of datasource groups, and can be used in mapper layer via annotations.

<code>@Mapper
@Sharding("mysql")
public interface UserMapper extends BaseMapper<User> {
    @Sharding("postgres")
    Long selectByUsername(String username);
}</code>

Custom sharding strategies can be defined by extending RandomShardingStrategy.

<code>@Component
public class MyShardingStrategy extends RandomShardingStrategy {
    @Override
    public void determineDatasourceKey(String group, Invocation invocation, SqlCommandType sqlCommandType) {
        this.changeDatabaseKey(group, sqlCommandType, keys -> chooseKey(keys, invocation));
    }
}</code>

Source code examples are available at https://gitee.com/baomidou/mybatis-mate-examples.

Maven dependencies

<code>&lt;dependency&gt;
  &lt;groupId&gt;com.baomidou&lt;/groupId&gt;
  &lt;artifactId&gt;mybatis-mate-starter&lt;/artifactId&gt;
  &lt;version&gt;1.0.1&lt;/version&gt;
&lt;/dependency&gt;</code>
<code>&lt;dependency&gt;
  &lt;groupId&gt;com.baomidou&lt;/groupId&gt;
  &lt;artifactId&gt;mybatis-mate-annotation&lt;/artifactId&gt;
  &lt;version&gt;1.0.1&lt;/version&gt;
&lt;/dependency&gt;</code>
backendJavaShardingMyBatisdata encryptionDDLDictionary Binding
Java Architecture Diary
Written by

Java Architecture Diary

Committed to sharing original, high‑quality technical articles; no fluff or promotional content.

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.