Computed Properties Directory
10/26/25About 1 min
Introduction
What are computed properties? Computed properties are not simple wrapper types or basic types, but properties derived through conversion functions or calculations.
Computed properties can be divided into two major categories: in-memory computed properties and database computed properties
Differences
| Computed Property | vo | Difference |
|---|---|---|
| In-memory computed property | If entity has @Column, then vo or dto must also have corresponding conversion | Function acts on the retrieved value, function will be applied to the value at the Java layer |
| Database computed property | vo or dto only needs property name consistency or manual as | Function acts at the database layer, retrieved value is already converted |
In-memory Computed Properties
jsonpropertyprivate UserExtra userExtra;used to describe database stored string or json type, mapped to java object, supports filtering, return sorting, etc.collectionpropertyprivate List<UserLabels> userLabels;used to describe database stored string or json type, mapped to java collection, supports filtering, return sorting, etc.- Enum property
private UserStatusEnum userStatus;used to describe database stored string or number type, mapped to java enum property, supports filtering, return sorting, etc.
Database Computed Properties
- Enhanced property
private String idCard;automatically addsbase64encoding when writing to database and automatically decodes when reading, supports filtering, return sorting, etc. - Simple computed property: composite property
private String fullName;it is composed offirstNameandlastName, or age, which is a dynamic value generated by subtracting the current time and birthday, supports filtering, return sorting, etc. - Status computed property: for example, you have a certificate table, the certificate table has certificate expiration time, then the certificate has a dynamic hidden property called status, whether the certificate has expired can be implemented through this status
- Complex computed property: composed of sub-table or additional table data, such as
private Integer StudentSize;if class and user are one-to-many, then this property is used to describe how many students are in the class, supports filtering sorting return - Function auto-increment property: this property can have data generated by the database, such as the database function has
mysqlNextId()orgisgenerated by the database function, then it is applicable to this method only effective when inserting
The difference between in-memory computed properties and database computed properties is
Contributors
只是我