Easy-Trans: A Spring Boot Plugin for Automatic Data Translation Across Services
Easy-Trans is a Spring Boot starter that leverages ORM frameworks like MyBatis‑Plus, JPA, and BeetlSQL to automatically translate IDs, dictionary codes, and enum values into human‑readable data, supporting caching, multi‑data‑source, micro‑service RPC, and flexible configuration for backend developers.
What is Easy-Trans – Easy-Trans is a code‑assistance plugin for data translation that uses ORM frameworks (MyBatis‑Plus, JPA, BeetlSQL) to automatically look up tables, allowing developers to quickly convert IDs or dictionary codes into display‑ready data for the frontend.
Key Advantages
Cache support
Cross‑microservice translation (e.g., translating a userId in the Order service to a userName from the User service)
Internationalization support
Adaptation to multiple ORM frameworks
Multi‑data‑source support
Collection support (e.g., translating a list of userIds to names)
Reverse translation (e.g., gender code to gender, name to userId)
Typical Scenarios
Displaying a user's position or name based on an ID without manual joins.
Translating dictionary codes such as "sex"=0 to "Male" for UI display.
Converting a batch of user IDs (1,2,3) to names like "Zhang San", "Li Si", "Wang Wu".
Showing enum field values (e.g., title) directly on the frontend.
Translating unique keys (phone number, ID number) to associated user information without manual queries.
Simple Configuration
For a Spring Boot project, add the Easy‑Trans starter dependency:
<!-- Current latest version is 2.2.1-M1 -->
<dependency>
<groupId>com.fhs-opensource</groupId>
<artifactId>easy-trans-spring-boot-starter</artifactId>
<version>2.2.1-M1</version>
</dependency>Then add the ORM‑specific extension, for example with MyBatis‑Plus:
<dependency>
<groupId>com.fhs-opensource</groupId>
<artifactId>easy-trans-mybatis-plus-extend</artifactId>
<version>2.2.1-M1</version>
</dependency>Configure Easy‑Trans in application.yml :
# Translation configuration
easy-trans:
# Flat mode
is-enable-tile: true
# Enable Redis cache
is-enable-redis: true
# Enable global responseBody interception for automatic translation
is-enable-global: true
# Use Redis for dictionary cache (recommended for micro‑service mode)
dict-use-redis: true
db-type: mysqlFlexible Usage
Easy‑Trans supports five translation types:
Dictionary Translation (TransType.DICTIONARY) – Users preload dictionary data into DictionaryTransService for cache‑based lookups.
Simple Translation (TransType.SIMPLE) – Automatically query the database via MyBatis‑Plus/JPA to map IDs to names and store results in transMap .
Cross‑Microservice Translation (TransType.RPC) – Uses REST calls between services; the calling service sends IDs, the provider service performs the lookup and returns the translated values.
AutoTrans (TransType.AUTO) – Allows custom translation logic without relying on ORM queries.
Enum Translation (TransType.ENUM) – Directly maps enum constants (e.g., SEX.BOY ) to human‑readable strings.
For a complete example, refer to the demo project at https://gitee.com/fhs-opensource/easy_trans_springboot_demo .
Summary
Official documentation can be found at http://easy-trans.fhs-opensource.top/components/readme.html . Interested developers are encouraged to explore further.
Sohu Tech Products
A knowledge-sharing platform for Sohu's technology products. As a leading Chinese internet brand with media, video, search, and gaming services and over 700 million users, Sohu continuously drives tech innovation and practice. We’ll share practical insights and tech news here.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.