为了账号安全,请及时绑定邮箱和手机立即绑定

在java中检查多个布尔条件

在java中检查多个布尔条件

温温酱 2021-07-27 13:49:19
我有一个场景,我必须检查模板是否已经存在于数据库中。如果存在,我必须根据现有模板返回一条消息。我有几个模板:电子邮件、信件、短信。如果它们都存在,我必须返回“所有模板都已经存在”。如果只有电子邮件模板存在,我必须返回只有电子邮件模板存在,信函和短信模板也是如此。代码:for (EventVO eventVO: eventModuleList) {    List <EmailTemplateMaster> emailTemplateList = communicationDAO        .checkEmailTemplateExist(eventVO.getEventCode());    if (CollectionUtils.isNotEmpty(emailTemplateList)) {        emailTemplateExist = true;    }    List <LetterTemplateMaster> letterTemplateList = communicationDAO        .checkLetterTemplateExist(eventVO.getEventCode());    if (CollectionUtils.isNotEmpty(letterTemplateList)) {        letterTemplateExist = true;    }    List <SmsTemplateMaster> smsTemplateList = communicationDAO        .checkSmsTemplateExist(eventVO.getEventCode());    if (CollectionUtils.isNotEmpty(smsTemplateList)) {        smsTemplateExist = true;    }    if (emailTemplateExist && letterTemplateExist && smsTemplateExist) {        templateExist = CommunicationConstants.ALL_TEMPLATE_EXIST;    }    if (emailTemplateExist || !letterTemplateExist && !smsTemplateExist) {        templateExist = CommunicationConstants.EMAIL_TEMPLATE_EXIST;    }    if (!emailTemplateExist && letterTemplateExist && !smsTemplateExist) {        templateExist = CommunicationConstants.LETTER_TEMPLATE_EXIST;    }    if (!emailTemplateExist && !letterTemplateExist && smsTemplateExist) {        templateExist = CommunicationConstants.SMS_TEMPLATE_EXIST;    }}我可以知道检查退出模板布尔值的最简单方法是否存在。基于退出,我必须发送相应的消息。public static final String ALL_TEMPLATE_EXIST = "Email, Letter and Sms Template already exist for the selected event."; public static final String EMAIL_TEMPLATE_EXIST = "Email Template already exist for the selected event.";public static final String SMS_TEMPLATE_EXIST = "Sms Template already exist for the selected event.";public static final String LETTER_TEMPLATE_EXIST = "Email Letter Template already exist for the selected event.";
查看完整描述

3 回答

  • 3 回答
  • 0 关注
  • 295 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信