无法使用 next() 前进

Could not advance using next()

我有一个对象列表,我想在 Spring 中 return 休息 API 然后将其作为对象数组读取在 Angular 中:

public Stream<PaymentTransactions> findListByReference_transaction_id(Integer id);

我试过这个:

@GetMapping("/reference_transaction_id/{id}")
public List<ResponseEntity<PaymentTransactionsDTO>> getByListReference_transaction_id(@PathVariable String id) {
    return transactionService
            .findListByReference_transaction_id(Integer.parseInt(id))
            .map(mapper::toDTO)
            .map(ResponseEntity::ok).collect(Collectors.toList());
}

但是当我尝试将其作为 Angular 数组读取时,我得到 could not advance using next() 从其余端点到 return 列表的正确方法是什么?

编辑:

@GetMapping("{id}")
    public ResponseEntity<List<ResponseEntity<PaymentTransactionsDTO>>> get(@PathVariable String id) {
        return ResponseEntity.ok(transactionService
                .findListById(Integer.parseInt(id)).stream()
                .map(mapper::toDTO)
                .map(ResponseEntity::ok).collect(Collectors.toList()));

修改了您的示例:

@GetMapping("/reference_transaction_id/{id}")
@ResponseBody
public ResponseEntity<List<PaymentTransactionsDTO>> getByListReference_transaction_id(@PathVariable Integer id) {
    try(var stream = transactionService
            .findListByReference_transaction_id(id)){
      var list = stream.map(mapper::toDTO).collect(Collectors.toList());
      return list.isEmpty() ? ResponseEntity.notFound().build() : ResponseEntity.ok(list) 
    }
}
  1. 将 ResponseBody 添加到您的方法中
  2. 用 try-with-resource 关闭流(我想你必须关闭它)
  3. 希望对你有用

关于您的 angular 问题。如果您发布一些源代码将会有所帮助:)