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字段类型处理器
原创:做时间的朋友
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 记一次.NET内存居高不下排查解决与启示