注释接口 Formula
This annotation is required by simple calculation property.
Example1: Simple calculation based on java/kt expression
public interface Employee {
... omit other properties...
String firstName();
String lastName();
@Formula(dependencies = {"firstName", "lastName"})
default String fullName() {
return firstName() + " " + lastName();
}
@ManyToOne
Department department();
@Formula(dependencies = "department")
default Long getDepartmentId() {
return department() != null ? department.getId() : null;
}
}
Example2: Simple calculation based on SQL expression(jimmer-trigger is not used)
public interface Employee {
... omit other properties...
String firstName();
String lastName();
@Formula(sql = "concat(FIRST_NAME, LAST_NAME)")
String fullName();
@ManyToOne
Department department();
@Formula(sql = "DEPARTMENT_ID")
Long getDepartmentId();
}
Example3: Simple calculation based on SQL expression(
jimmer-trigger is used and you hope
the event for formula property will be raised
when events for dependency properties are raised)
public interface Employee {
... omit other properties...
String firstName();
String lastName();
@Formula(
sql = "concat(FIRST_NAME, LAST_NAME)",
dependencies = {"firstName", "lastName"}
)
String fullName();
@ManyToOne
Department department();
@Formula(
sql = "DEPARTMENT_ID",
dependencies = "department"
)
Long getDepartmentId();
}
For complex calculation, please view
Transient,
`org.babyfish.jimmer.sql.TransientResolver` of jimmer-sql and
`org.babyfish.jimmer.sql.kt.KTransientResolver` of jimmer-sql-kotlin- 另请参阅:
-
可选元素概要
可选元素修饰符和类型可选元素说明String[]Property names, not columns names Only need to be specified when any of the following conditions are met The decorated property is non-abstract jimmer-trigger is used and you hope the events of the dependency fields can cause the event of current field.When the decorated property is abstract, It means the current property a simple calculation based on sql expression The `sql` of this annotation is required In this situation, the current property will be generated in not only `Draft` and `Fetcher` but also `Table`.
-
元素详细资料
-
sql
String sqlWhen the decorated property is abstract,- It means the current property a simple calculation based on sql expression
- The `sql` of this annotation is required
- In this situation, the current property will be generated in not only `Draft` and `Fetcher` but also `Table`. That means current formula property can be used by SQL-DSL
- In `Draft`, a function like `setXXX(Type value)` will generated
- It means the current property a simple calculation based on java/kotlin expression
- The `sql` of the annotation cannot be specified, but `dependencies` must be specified
- In this situation, the current property will be generated in not only `Draft` and `Fetcher`, but will not be generated in `Table`. That means current formula property cannot be used by SQL-DSL
- In `Draft`, a function like `useXXX()` will generated
- 默认值:
""
-
dependencies
String[] dependenciesProperty names, not columns names Only need to be specified when any of the following conditions are met- The decorated property is non-abstract
- jimmer-trigger is used and you hope the events of the dependency fields can cause the event of current field.
- For abstract formula property based on SQL expression, `dependencies` are optional, and they can only be scalar properties
- For non-abstract formula property based on java/kotlin expression, `dependencies` are required, and they can be not only scalar properties but also other formula properties. That means the formula property dependencies can be recursive
- 默认值:
{}
-