将属性添加到实体中的实例

时间:2017-10-25 08:46:32

标签: java spring

我有一个弹簧数据实体:

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

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

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

但是这些字段在我的服务之外是不可用的。

2 个答案:

答案 0 :(得分:1)

您可以引入新课程var imageUrl = 'https://cdn.sstatic.net/Sites/stackoverflow/img/sprites.svg'; var blob = null; var xhr = new XMLHttpRequest(); xhr.open('GET', imageUrl, true); xhr.responseType = 'blob'; xhr.onload = function() { blob = xhr.response; console.log(blob, blob.size); } xhr.send();

StorePrice

然后使用它代替class StorePrice { Store store; double maxPrice; double minPrice; }

Store

答案 1 :(得分:0)

你不能

在运行时(编译后)无法更改类。

相关问题