Column Annotation
The @Column annotation is used to specify the mapping relationship between entity fields and database table columns.
Parameters
| Parameter | Type | Default Value | Description |
|---|---|---|---|
value | String | "" | The name of the database column |
ignore | Boolean | false | Whether to ignore this column when generating SQL |
resultHandler | KClass<out ResultHandler> | ResultHandler::class | The result handler for this column |
Usage Example
java
import com.tang.kite.annotation.Column;
public class User {
private Long id;
@Column("user_name")
private String username;
@Column(ignore = true)
private String temporary;
@Column(resultHandler = GenderResultHandler.class)
private String gender;
}Custom Result Handler
The
ResultHandlerinterface allows to define custom result processing logic for special handling when query results are mapped to entity fields.
java
import com.tang.kite.result.ResultHandler;
import com.tang.kite.utils.Reflects;
import java.lang.reflect.Field;
public class GenderResultHandler implements ResultHandler {
// Custom default value for null
@Override
public <T> void setNullValue(Field field, T instance) {
Reflects.setValue(field, instance, "Not Specified");
}
@Override
public <T> void setValue(Field field, T instance, Object value) {
Reflects.setValue(field, instance, value);
}
}