0
我开发了一个Spring REST API,它从数据库(Postgres)中检索客户的调用首选项。Spring REST API:返回默认首选项
我有一个CallPreferences类,如下所示。
public class CallPreferences {
private Boolean allowInternationalCalling;
private Boolean allowInternationalRoaming;
private List<DataOptions> dataOptions;
private AutoPayPrefences autoPayPreferences;
// getter and setters.
}
以上所有首选项都保存在表格中的单个列中。在表中的一行可能看起来像下面
Customer_Id | customer_preferneces
10112 | "preferences": {"allowInternationalCalling": false,
"allowInternationalRoaming": true,
"dataOptions": ["plan" : "4GLTE",
"data-limit" : "10GB" ],
"autoPay": {"payment-option" : "creditcard",
"payment-date": "2nd every month",
"reminder": "email"}
}
我使用行映射到数据库中的喜好当没有在数据库中找到的喜好映射到POJO
,我要回应默认首选项如下。
"preferences": {
"allowInternationalCalling": true,
"allowInternationalRoaming": true,
"dataOptions": [],
"autoPay": {}
}
我知道我们可以在类级别初始化值,或者如果首选项== null,我可以为每个属性设置默认值。但想知道是否有更好的方法使用弹簧功能来做到这一点。
如何重载构造函数? – jitsonfire