What is Mybatis-Flex
Mybatis-Flex is an elegant Mybatis enhanced framework, which is very lightweight and has high performance and flexibility. We can easily use Mybaits-Flex to link any database, and its built-in QueryWrapper^ highlights help us greatly reduce the work of SQL writing and reduce the possibility of errors.
All in all, Mybatis-Flex can greatly improve our development efficiency and development experience, allowing us to have more time to focus on our own things.
feature
1. Lightweight : Except for MyBatis, there is no third-party light dependency and no interceptors. The principle is light implementation through SqlProvider. At the same time, in the process of execution, there is no Sql parsing (Parse) light operation. This brings several benefits: 1. Extremely high performance; 2. Very easy to track and debug the code; 3. Higher controllability.
2. Flexible : While supporting the addition, deletion, modification and query of Entity, and paging query, Mybatis-Flex provides Db + Row^ flexible tools, which can add, delete, modify and query the database without entity classes and paging query. At the same time, Mybatis-Flex's built-in QueryWrapper^ is flexible and can easily help us realize common SQL scenarios such as multi-table query , link query , and subquery .
3. Powerful : It supports any relational database, and can continue to expand through dialects. It also supports multiple (composite) primary keys , logical deletion , optimistic lock configuration , data desensitization , data auditing , data filling and other functions.
function comparison
- MyBatis-Plus: The old MyBatis enhanced framework
- Fluent-Mybatis: Mybatis enhanced framework developed by Ali (is it developed by Ali?)
function or feature | MyBatis-Flex | MyBatis-Plus | Fluent-Mybatis |
---|---|---|---|
Basic addition, deletion, modification and query of entity | ✅ | ✅ | ✅ |
Paging query | ✅ | ✅ | ✅ |
Total cache for paged queries | ✅ | ❌ | ❌ |
Paging query without SQL analysis design (lighter) | ✅ | ❌ | ✅ |
Multi-table query: from multiple tables | ✅ | ❌ | ❌ |
Multi-table queries: left join, inner join, etc. | ✅ | ❌ | ✅ |
Single primary key configuration | ✅ | ✅ | ✅ |
Multiple id generation strategies | ✅ | ✅ | ✅ |
Support multiple primary keys and composite primary keys | ✅ | ❌ | ❌ |
field typeHandler configuration | ✅ | ✅ | ✅ |
Except Mybatis, no other third-party dependencies (lighter) | ✅ | ❌ | ❌ |
Tombstone | ✅ | ✅ | ✅ |
optimistic lock | ✅ | ✅ | ✅ |
SQL Audit | ✅ | ❌ | ❌ |
data padding | ✅ | ✅ (for a fee) | ✅ |
data desensitization | ✅ | ✅ (for a fee) | ❌ |
field permissions | ✅ | ✅ (for a fee) | ❌ |
field encryption | ✅ | ✅ (for a fee) | ❌ |
dictionary echo | ✅ | ✅ (for a fee) | ❌ |
Db + Row | ✅ | ❌ | ❌ |
Entity monitoring | ✅ | ❌ | ❌ |
Multiple data source support | ✅ | ✅ | ❌ |
Comparison function reference address: Compared with Mybatis-plus, Mybatis-Flex v1.0.7 is released- OSCHINA - Chinese Open Source Technology Exchange Community
data desensitization
Data Desensitization- Mybatis-Flex Official Website
What is data desensitization
With the promulgation and implementation of the "Network Security Law", the protection of personal privacy data has risen to the legal level. Data desensitization refers to the transformation of certain sensitive information through desensitization rules to achieve reliable protection of sensitive private data. In the case of customer security data or some commercially sensitive data, the real data shall be transformed and provided for use without violating system rules, such as ID number, mobile phone number, card number, customer number and other personal information. Data desensitization.
@ColumnMask
Mybatis-Flex provides @ColumnMask()
annotations and 9 built-in desensitization rules to help developers easily desensitize data. For example:
java
@Table("tb_account")
public class Account {
@Id(keyType = KeyType.Auto)
private Long id;
@ColumnMask(Masks.CHINESE_NAME)
private String userName;
}
In the above example, CHINESE_NAME
the desensitization rule of is used, which is mainly used to deal with the "Chinese name" scenario. When we query that userName is 张三丰
, its content is automatically processed 张**
.
In addition, Mybatis-Flex also provides the following 8 desensitization rules, which are convenient for developers to use directly:
- Mobile phone number desensitization
- Landline Desensitization
- ID number desensitization
- ID number desensitization
- Address desensitization
- email desensitization
- password desensitization
- Bank card number desensitization
Custom desensitization rules
When the 9 built-in desensitization rules of Mybaits-Flex cannot meet the requirements, we can also customize the desensitization rules, and the steps are as follows:
1. MaskManager
Register a new desensitization rule via :
java
MaskManager.registerMaskProcesser("自定义规则名称"
, data -> {
return data;
})
2. Use custom desensitization rules
java
@Table("tb_account")
public class Account {
@Id(keyType = KeyType.Auto)
private Long id;
@ColumnMask("自定义规则名称")
private String userName;
}
Cancel desensitization
In some scenarios, the program hopes to query the original data instead of desensitized data. For example, to query the user's mobile phone number, and then send a text message to the user. In other words, we enter the edit page to edit user data. If the edit page displays desensitized data, and then click Save again, the real data in the database will also be desensitized and overwritten.
Therefore, MaskManager provides skipMask
two restoreMask
methods to handle this scenario:
java
try {
MaskManager.skipMask()
//此处查询到的数据不会进行脱敏处理
accountMapper.selectListByQuery(...)
} finally {
MaskManager.restoreMask()
}
hint
In a specific application, we usually put skipMask()
and restoreMask()
into a unified interceptor to uniformly intercept and process a certain type of business.