Skip to content

Column Annotation

The @Column annotation is used to specify the mapping relationship between entity fields and database table columns.

Parameters

ParameterTypeDefault ValueDescription
valueString""The name of the database column
ignoreBooleanfalseWhether to ignore this column when generating SQL
resultHandlerKClass<out ResultHandler>ResultHandler::classThe 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 ResultHandler interface 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);
    }

}

Built with ❤️ by Tang