线上项目小坑

数据类型的比较

今天做个需求时:就是简单的三级分类,分类代码如下:

    @Override
    public List<CategoryEntity> queryListTree(Map<String, Object> params) {
        List<CategoryEntity> categoryEntities = baseMapper.selectList(null);
        //System.out.println(categoryEntities);
        List<CategoryEntity> entityList = categoryEntities.stream().filter(categoryEntity -> categoryEntity.getParentCid() == 0)
                .map(categoryEntity -> {
                    // 得到孩子
                    categoryEntity.setChildren(getChildren(categoryEntities, categoryEntity));
                    return categoryEntity;
                }).collect(Collectors.toList());
        System.out.println(entityList);
        return entityList;
    }
    private List<CategoryEntity> getChildren(List<CategoryEntity> categoryEntities,
                                             CategoryEntity category){
        List<CategoryEntity> collect = categoryEntities.stream().filter(entity ->{
            return entity.getParentCid() == category.getCatId();
        }).map(entity -> {
            entity.setChildren(getChildren(categoryEntities, entity));
            return entity;
        }).collect(Collectors.toList());
        return collect;

    }

return entity.getParentCid() == category.getCatId();里面这段代码,id是Long类型,不属于基本类型,这里出了大bug,在添加分类时,发现这里比较是false,后来经过debug知道这里出了问题。

    public static Long valueOf(long l) {
        final int offset = 128;
        if (l >= -128 && l <= 127) { // will cache
            return LongCache.cache[(int)l + offset];
        }
        return new Long(l);
    }

数据在-128到127才会自动拆包为基本数据类型。fuck
其实这里知识点很简单,但是写业务时很容易忘记,最好所有都用equals

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值