if (flag && StringUtils.isNull(equSysEquipment)) {//配置设备 return configurationEquipmentMapper.addAlarmConfigurationEquipment(equipment); } else if (!flag && StringUtils.isNotNull(equSysEquipment)) {//取消配置设备 return configurationEquipmentMapper.deleteAlarmConfigurationEquipment(equipment); }代码怎么简化
时间: 2024-02-23 13:02:41 浏览: 41
javascript if 的简化代码
这段代码已经比之前的简化程度更高了,直接返回结果即可,可以进一步简化为如下代码:
```
return flag && StringUtils.isNull(equSysEquipment) ? configurationEquipmentMapper.addAlarmConfigurationEquipment(equipment)
: !flag && StringUtils.isNotNull(equSysEquipment) ? configurationEquipmentMapper.deleteAlarmConfigurationEquipment(equipment)
: null;
```
这样的代码更加简洁,同时也减少了代码行数,提高了代码的可读性。
阅读全文