【发布时间】:2020-09-14 07:19:09
【问题描述】:
我有一个 ResponseDto 类,如下所示:
public static class HealthGoalsHighlight {
@ApiModelProperty(value = "Total number of eligible users")
private Long totalEligibleUsers;
@ApiModelProperty(value = "Total number of registered users")
private Long totalRegisteredUsers;
@ApiModelProperty(value = "Total number of users with atleast one goal count")
private Long totalUsersWithGoal;
@ApiModelProperty(value = "Top goal name selected by user")
private String topGoal;
@ApiModelProperty(value = "Bottom goal name selected by user")
private String bottomGoal;
}
此 DTO 是根据下表结构制作的:
health_goals
(
uid BIGSERIAL NOT NULL CONSTRAINT health_goals_pkey primary key,
employer_key bigint not null,
total_eligible_users bigint not null,
total_registered_users bigint not null,
total_users_with_goal bigint not null,
top_goal_name varchar(255),
bottom_goal_name varchar(255),
created_ts TIMESTAMP NOT NULL DEFAULT NOW(),
updated_ts TIMESTAMP NOT NULL DEFAULT NOW(),
created_by varchar(255),
updated_by varchar(255)
);
现在表结构已更改为:
health_goals
(
uid BIGSERIAL NOT NULL CONSTRAINT health_goals_pkey primary key,
employer_key bigint not null,
health_goals_metric_value json null,
created_ts TIMESTAMP NOT NULL DEFAULT NOW(),
updated_ts TIMESTAMP NOT NULL DEFAULT NOW(),
created_by varchar(255),
updated_by varchar(255)
);
现在基本上所有这些列,如total_eligible_users、total_registered_users、total_users_with_goal、top_goal_name、bottom_goal_name 将被合并为单个列health_goals_metric_value 作为 JSON 数据类型。
如何为 JSON 数据类型列编写响应 DTO。另外,我的 AggMapper 类中需要进行哪些更改。
【问题讨论】:
-
请分享您现有的 AggMapper 类的代码。
标签: java json hibernate spring-boot spring-mvc