mybatis-plus 直接查询的数据对对象带嵌套的对象

1.java entity定义

@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
@TableName(value = "delta24_alarmrule",autoResultMap = true)
public class AlarmRuleNew extends BaseEntity {
    private static final long serialVersionUID = 1L;

    private String ruleKey;
    @TableField(typeHandler = JacksonTypeHandler.class)
    private AlarmRuleDefinition definition;
    private String srcMetric;
    private RelationalSymbol expression; // >
    private String threshold; // 90.00
    private AlarmScopeTypeEnum scope; // resourceId,group
    private Integer windowSize;
    private Integer windowSlide;
    private Integer hitNumber;
    private Integer restrain; // 收敛时间
    private TimeUnit restrainTimeunit; // 收敛单位
    private AlarmLevel level;
    private Boolean alarmEnable;
    private Boolean notifyEnable;

    @TableField(value = "resgroup_code")
    private String resGroupCode;

    public static final String LEVEL_COLUMN = "level";
    public static final String METRIC_COLUMN = "src_metric";
    public static final String RULE_KEY_COLUMN = "rule_key";
    public static final String RES_GROUP_CODE_COLUMN = "resgroup_code";

}

2.核心说明

@TableName注解是mybatisplus包提供

com.baomidou.mybatisplus.annotation.TableName;

value属性

指定数据库中对应的表名

autoResultMap属性

autoResultMap = true 代表开启自动映射,可以将库里存储的json数据查询及写入的时候自动转换成json格式

3.相关嵌套对象依赖@TableFiled注解

@TableField(typeHandler = JacksonTypeHandler.class)
private AlarmRuleDefinition definition;

TableField注解

typeHandler属性

typeHandler = JacksonTypeHandler.class
JacksonTypeHandler是mybatis-plus中提供的json字段类型处理器

posted @ 2023-01-15 11:18  SpecialSpeculator  阅读(1526)  评论(0编辑  收藏  举报