我正在使用Spring Cloud从其他服务请求数据。因此,基本上,我需要数据,我想检索该数据并将其分配给另一个对象,该对象将是我要保存的对象。
这是我的代码:
Dim wsCopy_F19 As Long
Dim wsCopy_Transfer As Long
Dim wsCopy_Travel As Long
Dim wsCopy As Worksheet
Dim numWs As Double
Dim i As Double
Dim wsCopyName As String
Dim Target1 As Range
Dim Target2 As Range
Dim Target3 As Range
numWs = wbCopy.Worksheets.Count
For i = 0 To numWs
wsCopy = wbCopy.Worksheets(i)
wsCopyName = wsCopy.Name
If wsCopyName = "FY19 Source" Then
wsCopy_F19 = wsCopy.Cells(Rows.Count, 1).End(xlUp).Row
Set Target1 = wsCopy.Range("A2:M" & wsCopy_F19)
Target1.Copy Destination:=wsMSTR_XXF19.Range("A" & rowMSTR_F19).PasteSpecial(xlPasteValues)
rowMSTR_F19 = wsMSTR_XXF19.Cells(Rows.Count, 1).End(xlUp).Row + 1
ElseIf InStr(wsCopyName, "Transfer") > 0 Then
wsCopy_Transfer = wsCopy.Cells(Rows.Count, 1).End(xlUp).Row
Set Target2 = wsCopy.Range("A2:M" & wsCopy_Transfer)
Target2.Copy Destination:=wsMSTR_Transfer.Range("A" & rowMSTR_Transfer).PasteSpecial(xlPasteValues)
rowMSTR_Transfer = wsMSTR_Transfer.Cells(Rows.Count, 1).End(xlUp).Row + 1
ElseIf wsCopyName = "Travel-Events Calendar" Then
wsCopy_Travel = wsCopy.Cells(Rows.Count, 1).End(xlUp).Row
Set Target3 = wsCopy.Range("A2:M" & wsCopy_Travel)
Target3.Copy Destination:=wsMSTR_Travel.Range("A" & rowMSTR_Travel).PasteSpecial(xlPasteValues)
rowMSTR_Travel = wsMSTR_Travel.Cells(Rows.Count, 1).End(xlUp).Row + 1
Else
End If
Next
但是我有一个例外:
public Mono<Shops> save(Shops shops) {
Mono<Shops> s = webClientBuilder.build().get()
.uri("http://mysql-app/api/reservation-passengers/boarding-pass-data/" + shops.getBoardingPassId().toString())
.exchange()
.flatMap(response -> {
Shops myShops = response.bodyToMono(Shops.class).block();
shops.setAirportDestiny(myShops.getAirportDestiny());
shops.setCustomerId(myShops.getCustomerId());
return shopsRepository.save(shops);
});
return s;
}
如何从异步方法获取数据?
答案 0 :(得分:0)
我找到了解决方案。我不得不稍微修改一下代码。
public Mono<Shops> save(Shops shops) {
Mono<BoardingPassDTO> response = webClientBuilder.build().get()
.uri("http://mysql-app/api/reservation-passengers/boarding-pass-data/"
+ shops.getBoardingPassId().toString())
.retrieve().bodyToMono(BoardingPassDTO.class);
return response.flatMap(r ->{
shops.setAirportDestiny(r.getAirportArrivalId());
shops.setCustomerId(r.getPassengerId());
shops.setShopDate(LocalDateTime.now());
return shopsRepository.save(shops);
});
}