【发布时间】:2021-07-02 18:17:14
【问题描述】:
给定:
-
带有控制器方法的反应链
@PostMapping("/add") public Mono<String> addSkill(@ModelAttribute Skill skil) { log.info("skill "+ skill.getName() + " has been added!"); return service.add(skill) .then(Mono.just(TEMPLATE)); @GetMapping("") public Mono<String> getAll(Model model) { IReactiveDataDriverContextVariable driverContextVariable = new ReactiveDataDriverContextVariable(service.findAll(), 100); model.addAttribute("skills", driverContextVariable); return Mono.just(TEMPLATE);} -
表格:
<div class="row">
<div id="title">
<h1>Reactive java skills</h1>
</div>
<table id="allSkills" class="table table-striped">
<thead>
<tr>
<th>Name</th>
<th>Level</th>
<th>Priority</th>
<th>Skill Group</th>
</tr>
</thead>
<tbody>
<tr class="skills" data-th-each="skill : ${skills}">
<td>[[${skill.name}]]</td>
<td>[[${skill.level}]]</td>
<td>[[${skill.priority}]]</td>
<td>[[${skill.skillGroupName}]]</td>
</tr>
</tbody>
</table>
</div>
<div>
<h4>add skill</h4>
<form th:action="@{/skill/add}" th:object="${skill}" method="post">
<input type="text" th:field="*{skill.name}" placeholder="choose skill name"/>
<input type="text" th:field="*{skill.level}" placeholder="choose skill level"/>
<input type="text" th:field="*{skill.priority}" placeholder="choose skill priority"/>
<input type="text" th:field="*{skill.skillGroupName}" placeholder="choose skill priority"/>
<input type="submit" value="Submit" /> <input type="reset" value="Reset" />
</form>
</div>
我的目标很简单:通过提交表单来添加一个新实体并渲染它 显示所有实体的 html。据我了解 Reactive Thyme 的概念,这里没有 @PathVariable 由于它背后的阻塞代码,所以我使用 @ModelAttribute 来传递新技能的参数。但是,当我请求控制器的基本路径时,它会呈现所有技能并抛出:
java.lang.IllegalStateException: 既不是 BindingResult 也不是普通的 bean 名称“技能”的目标对象可用作请求属性
当我渲染页面并仅在提交表单时使用它时,我没有胶水如何让 thymeleaf 忽略 ${skill} 参数。
PS - 我还没有找到反应性百里香的官方文档,如果有人分享链接,那就太棒了。
【问题讨论】:
-
哦,我忘了注意,除了 IllegalStateException,它会渲染 getAll(Model model) 实体,但根本不会渲染输入的形式。
标签: thymeleaf