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
operatorColumnOperatorColumnOperator.EQUALSQL operator (such as EQUAL) can be used for condition entity

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;

    @Column(operator = ColumnOperator.LIKE)
    private String nickname;

}

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);
    }

}

Setting SQL Operator ​

ColumnOperator enum defines common SQL operators, which can be specified through the operator parameter of the @Column annotation.

The default is EQUAL, which means using the equals operator.

sql
# @Column(operator = ColumnOperator.LIKE)
where nickname like '%value%'

# @Column(operator = ColumnOperator.GT)
where age > value

# @Column(operator = ColumnOperator.IS_NULL)
where deleted_time is null

Released under the MIT License