代码优化 if (recordList.size() == 1) { if (project.getTheTone() != null && recordList.get(0).getAmount() == project.getTheTone()) { context.put("tradeMethod", "一次性付款"); } if (project.getTheTone() != null && recordList.get(0).getAmount() != project.getTheTone()) { context.put("tradeMethod", "分期付款"); } if (project.getTheTone() == null && recordList.get(0).getAmount() == dealRecord.getDealPrice()) { context.put("tradeMethod", "一次性付款"); } if (project.getTheTone() == null && recordList.get(0).getAmount() != dealRecord.getDealPrice()) { context.put("tradeMethod", "分期付款"); } } else { context.put("tradeMethod", "分期付款"); }
时间: 2023-12-10 22:03:16 浏览: 146
可以考虑将代码中的重复逻辑进行简化,如下所示:
```
if (project.getTheTone() != null) {
if (recordList.size() == 1) {
if (recordList.get(0).getAmount() == project.getTheTone()) {
context.put("tradeMethod", "一次性付款");
} else {
context.put("tradeMethod", "分期付款");
}
} else {
context.put("tradeMethod", "分期付款");
}
} else {
if (recordList.size() == 1) {
if (recordList.get(0).getAmount() == dealRecord.getDealPrice()) {
context.put("tradeMethod", "一次性付款");
} else {
context.put("tradeMethod", "分期付款");
}
} else {
context.put("tradeMethod", "分期付款");
}
}
```
上述代码中,将原本分为四个if-else语句的逻辑合并成两个if-else语句,通过嵌套判断实现了代码的优化。同时,在判断一次性付款和分期付款时,也将重复的代码进行了简化。
阅读全文