gpt4 book ai didi

java - 向实体中的实例添加属性

转载 作者:行者123 更新时间:2023-12-02 12:05:37 24 4
gpt4 key购买 nike

我有一个 Spring 数据实体:

public class Product{
private Store minStore;
private Store maxStore;
private List<Store> stores;
}

我的商店类别由一个字段组成 - 商店名称。但我需要在 minStore 和 maxStore 中添加其他字段 - double minPrice(MinStore)、double maxPrice(MaxStore)。我不需要将此字段添加到商店类中,那么如何将此属性添加到实例中?在我的 Spring 服务中,我可以做这样的事情 -

maxStore = new Store(storeName,offers){
double maxPrice = salePrice ;
public void setMaxPrice(double maxPrice){
this.maxPrice = maxPrice;
}
public double getMaxPrice(){
return this.maxPrice;
}
};

但此字段在我的服务之外不可用。

最佳答案

您可以引入新类StorePrice:

class StorePrice {
Store store;
double maxPrice;
double minPrice;
}

然后使用它代替Store

public class Product{
private Store minStore;
private Store maxStore;
private List<StorePrice> stores;
}

关于java - 向实体中的实例添加属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46927879/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com