integer判断值相等

2021-01-25  本文已影响0人  尘埃里的玄

今天我烦了一个迷糊,其实这个知识点我之前面试的复习到,今天在编码中又掉到坑里去了


image.png

我发现我的值怎么全是0
然后打断点调试发现我的判断条件就没有跳进去过
我就知道是我的integer的判断值相等除了问题

    public List<EnergyDepartmentInfoVO> getDepartmentEnergyInfo(){
        List<EnergyDepartmentInfoVO> departmentEnergyInfos = setDepartmentBaseInfo();
        //拿到近三年主要部门的电表数据
        List<ElectricityStatementByRecentYear> electricityStatementByRecentYears = iLoadComprehensiveEnergyConsumption.loadRecentYearElectricity(years);
        //填充departmentEnergyInfos的电力数据
        for (ElectricityStatementByRecentYear electricityStatementByRecentYear : electricityStatementByRecentYears) {
            for (EnergyDepartmentInfoVO departmentEnergyInfo : departmentEnergyInfos) {
                if (electricityStatementByRecentYear.getPartment() == departmentEnergyInfo.getDepartmentID() && electricityStatementByRecentYear.getSelectYear() == departmentEnergyInfo.getYear()){
                    departmentEnergyInfo.setMeter(electricityStatementByRecentYear.getMeterAmount());
                    break;
                }
            }
        }

出错代码:

electricityStatementByRecentYear.getPartment() == departmentEnergyInfo.getDepartmentID() && electricityStatementByRecentYear.getSelectYear() == departmentEnergyInfo.getYear()
//用于取出主要部门的三年的电份用电量的结果集的实体类
@Data
public class ElectricityStatementByRecentYear {
    @ApiModelProperty(value = "部门id")
    private Integer partment;
    @ApiModelProperty(value = "选择的年份")
    private Integer selectYear;
    @ApiModelProperty(value = "年费的用电量")
    private Double meterAmount;
}

@Data
public class EnergyDepartmentInfoVO implements Serializable {
    @ApiModelProperty(value = "部门ID")
    private Integer departmentID;
    @ApiModelProperty(value = "年份")
    private Integer year;
    @ApiModelProperty(value = "部门名称")
    private String departmentName;
    @ApiModelProperty(value = "部门人数")

我的两个属性都是integer。
所以应该使用equals方法
具体原理参考博客:
https://www.jianshu.com/p/9cb9c61b0986

上一篇下一篇

猜你喜欢

热点阅读