【问题标题】:how to multily two fields from two different collections如何将两个不同集合中的两个字段相乘
【发布时间】:2021-09-18 22:51:13
【问题描述】:

我在 mongodb sring boot 中有两个集合:

public class StampOperation {

    @Id
    private String id;

    private int addedQuantity;
    private int previousQuantity;
    private int remainingQuantity;

    @JsonFormat(pattern="dd/MM/yyyy")
    private Date operationDate;

    @DBRef
    private TaxStamp taxStamp;
}


public class TaxStamp 
{
    @Id
    private String id;

    private String name;
    private double value;
    private EType stampType;
    private int globalInitialQuantity;
    private int minimumThreshold;

}

有没有什么方法可以将 StampOperation 中的 addedQuantity 乘以 TaxStamp 中的值?

【问题讨论】:

    标签: java mongodb spring-boot collections aggregate


    【解决方案1】:

    如果我正确理解您的问题,您想知道如何将两个不同对象的两个值相乘。

        double result = stampOperation.addedQuantity * taxStamp.value;
    

    要执行此操作,您需要准备好这两个类的引用实例。此外,应该使用的属性(addedQuantity 和 value)需要是可访问的。这可以通过例如将它们标记为公开。

    【讨论】:

    • 非常感谢您这么快回答,但我不明白“您需要手头有两个类的引用实例”是什么意思
    猜你喜欢
    • 1970-01-01
    • 2017-12-25
    • 2014-11-09
    • 1970-01-01
    • 2015-11-05
    • 2012-08-23
    • 1970-01-01
    • 2011-07-25
    • 1970-01-01
    相关资源
    最近更新 更多