实体对象为null小记

以下是Service.java的一个方法 

  @Override
    public AuthAccountDTO getAccountInfo(Long id) {
        AuthAccountDO accountDO = this.authAccountMapper.selectByPrimaryKey(id);
        AuthAccountDTO accountDTO = new AuthAccountDTO();
        if (accountDO == null) {
//            throw new BusinessException(AuthBusinessError.SYS_DATA_NOT_EXISTS_ERROR, "员工信息不存在");
            logger.info("员工信息不存在 {} id :"+ JsonUtil.toJson(id));
            return null;
        }

        BeanUtils.copyProperties(accountDO, accountDTO);

        return accountDTO;
    }

如果this.authAccountMapper.selectByPrimaryKey(id)返回值为Null,即查询数据为空,那么accountDo=null,再用下边的if判断就能走到方法里,而如果是

AuthAccountDO accountDO = new AuthAccountDO 
if(accountDO == null){
    logger.info("员工信息不存在 {} id :"+ JsonUtil.toJson(id));   //if判断是不会走到方法里的,非null
}

菜鸟一枚,记得都是最简单的

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值