美文网首页
lambda实战技巧

lambda实战技巧

作者: hemingkung | 来源:发表于2020-07-03 11:49 被阅读0次
查询实体类
判空异常抛出
Model model = modelDao.findById(groupAddParam.getModelId())
.orElseThrow(
() -> new ServiceException(APIResultEnum.NON_EXIST, "Model")
);


ConvertUtils.assertThrow(
!groupAddParam.getModelId().equals(template.getModel().getId()),
 () -> new ServiceException(APIResultEnum.MODEL_DIFFERENT, "Group/Template"));



Group entity = Optional.ofNullable(
groupDao.findByIdAndCompanyId(groupUpdateParam.getId(), companyId))
.orElseThrow(() -> {
            log.info("[GroupService]Group信息不存在: groupId={}, companyId={}", groupUpdateParam.getId(), companyId);
            return new ServiceException(APIResultEnum.NON_EXIST, "Group");
        });




相关文章

网友评论

      本文标题:lambda实战技巧

      本文链接:https://www.haomeiwen.com/subject/gjyyfktx.html