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 @   SpecialSpeculator  阅读(1586)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 记一次.NET内存居高不下排查解决与启示
点击右上角即可分享
微信分享提示