是否有可能以某种方式更改下面的代码,因此,如果未提供status
值以返回存储在数据库中的所有PaymentLog对象,而不是仅返回status
与404
相等的对象?基本上,我想如果没有提供status
变量来调用服务层中的另一个方法logService.getAllPaymentLogs()
@GetMapping(Endpoints.LOGS.PAYMENT_LOGS)
public Page<PaymentLog> getPaymentLog(@RequestParam Optional<Integer> status) {
return logService.getPaymentLogStatus(status.orElse(404), PageRequest.of(0, 10));
}
这些是getPaymentLogStatus()
和getAllPaymentLogs
@Override
public Page<PaymentLog> getPaymentLog(Pageable pageable) {
return paymentLogRepository.getAllBy(pageable);
}
和
@Override
public Page<PaymentLog> getPaymentLog(int status, Pageable pageable) {
return paymentLogRepository.getAllByStatus(status, pageable);
}
@@ 123在评论会话中回答了问题:
status.map(s -> getPaymentLog(s, page)).orElseGet(() -> getPaymentLog(page))