如何在 Thymeleaf + spring boot 控制器中显示来自 Flux 的数据
How to display data from Flux in Thymleaf + springboot controller
我正在尝试显示从 Corda 节点收到的进度跟踪器信息。我正在使用 ReactiveDataDriverContextVariable
设置为 Springboot 控制器/ Thymeleaf 中控制器模型的属性,但它不起作用,它只显示我的变量的地址。
我试过这个 site
中的教程
我的控制器看起来像(我设法从 Progresss tracker observable myFlux 创建了一个 Flux
)
public String index(final Model model) {
// loads 1 and display 1, stream data, data driven mode.
IReactiveDataDriverContextVariable reactiveDataDrivenMode =
new ReactiveDataDriverContextVariable(myFlux, 100);
model.addAttribute("progressTracker", reactiveDataDrivenMode);
return "index";
}
我的 thymleaf 视图
<table id="Progress" class="table table-striped">
<thead>
<tr>
<th width="70%">Step</th>
</tr>
</thead>
<tbody>
<tr class="result" data-th-each="step: ${progressTracker}">
<td>[[${step}]]</td>
</tr>
</tbody>
</table>
当您说 "displaying the address of my variable" 时,我相信它是您所指的散列对象散列,由于缺少适当的 toString() 方法而正在打印。
我相信您正在尝试打印 observable 而不是订阅它。例如,当您执行以下操作时,它并没有像您尝试打印可观察对象那样做很多事情。
val handle = proxy.startTrackedFlow(::MyFlow, val1, val2);
println(handle.progress);
你实际上应该做的是:
val handle = proxy.startTrackedFlow(::MyFlow, val1, val2);
handle.progress?.subscribe {
println(it)
}
它应该打印进度步骤。
我正在尝试显示从 Corda 节点收到的进度跟踪器信息。我正在使用 ReactiveDataDriverContextVariable
设置为 Springboot 控制器/ Thymeleaf 中控制器模型的属性,但它不起作用,它只显示我的变量的地址。
我试过这个 site
中的教程我的控制器看起来像(我设法从 Progresss tracker observable myFlux 创建了一个 Flux
)
public String index(final Model model) {
// loads 1 and display 1, stream data, data driven mode.
IReactiveDataDriverContextVariable reactiveDataDrivenMode =
new ReactiveDataDriverContextVariable(myFlux, 100);
model.addAttribute("progressTracker", reactiveDataDrivenMode);
return "index";
}
我的 thymleaf 视图
<table id="Progress" class="table table-striped">
<thead>
<tr>
<th width="70%">Step</th>
</tr>
</thead>
<tbody>
<tr class="result" data-th-each="step: ${progressTracker}">
<td>[[${step}]]</td>
</tr>
</tbody>
</table>
当您说 "displaying the address of my variable" 时,我相信它是您所指的散列对象散列,由于缺少适当的 toString() 方法而正在打印。
我相信您正在尝试打印 observable 而不是订阅它。例如,当您执行以下操作时,它并没有像您尝试打印可观察对象那样做很多事情。
val handle = proxy.startTrackedFlow(::MyFlow, val1, val2);
println(handle.progress);
你实际上应该做的是:
val handle = proxy.startTrackedFlow(::MyFlow, val1, val2);
handle.progress?.subscribe {
println(it)
}
它应该打印进度步骤。