java - Spring Boot,Thymeleaf 表单错误 => 我想从表中选择编辑行
问题描述
我想在另一个 html 页面中编辑表格的一行。我有一个 thymeleaf 和 Spring MVC 的初学者......
profileAll.html
但是,我有这个错误: org.thymeleaf.exceptions.TemplateProcessingException:执行处理器'org.thymeleaf.spring5.processor.SpringInputRadioFieldTagProcessor'时出错(模板:“profilsAll” - 第 39 行,第 26 列) ....
原因:java.lang.IllegalStateException:Bean 名称“profil”的 BindingResult 和普通目标对象都不能用作请求属性
ProfilesAll.html:
<form th:action="@{/profiles/update}" th:object="${profil}" method="POST">
<table border="1">
<thead>
<tr>
<th>Select</th>
<th>UID</th>
<th>SIP</th>
<th>enterpriseVoiceEnabled</th>
<th>voicePolicy</th>
<th>dialPlan</th>
<th>samAccountName</th>
<th>exUmEnabled</th>
<th>exchUser</th>
<th>objectClass</th>
<th>statusProfile</th>
</tr>
</thead>
<tbody>
<tr th:if="${skypeProfiles.empty}">
<td colspan="2"> No skype profile available </td>
<tr th:each="skypeProfile, profile:${skypeProfiles}">
<td>
<input type="radio" th:field="*{profile}" th:value="${profile}" />
</td>
<td th:text=${skypeProfile.collaboraterId}>UID</td>
<td th:text=${skypeProfile.SIP}>SIP</td>
<td th:text=${skypeProfile.enterpriseVoiceEnabled}>enterpriseVoiceEnabled</td>
<td th:text=${skypeProfile.voicePolicy}>voicePolicy</td>
<td th:text=${skypeProfile.dialPlan}>dialPlan</td>
<td th:text=${skypeProfile.samAccountName}>samAccountName</td>
<td th:text=${skypeProfile.exUmEnabled}>exUmEnabled</td>
<td th:text=${skypeProfile.exchUser}>exchUser</td>
<td th:text=${skypeProfile.objectClass}>objectClass</td>
<td th:text=${skypeProfile.statusProfile}>statusProfile</td>
</tr>
</tbody>
</table>
<button type="submit" value ="Edit">Edit</button>
</form>
控制器 :
@PostMapping("profiles/update")
public String profilesUpdate(@ModelAttribute("profil") SkypeProfileSearchBean skypeProfile) {
System.out.print("skypeProfile id "+skypeProfile.getCollaboraterId());
return "profilsUpdate";
}
这段代码有问题,但我没有找到解决方案:
<input type="radio" th:field="*{profile}" th:value="${profile}" />
非常感谢您的帮助
解决方案
您无需拥有两个 skypeProfiles 实例即可在对象中使用一个并显示一个。只要有一个实例就足够了。参考 - https://www.baeldung.com/spring-boot-crud-thymeleaf
替换<tr th:each="skypeProfile, profile:${skypeProfiles}">
为 <tr th:each="skypeProfile : ${skypeProfiles}">
并 <input type="radio" th:field="*{profile}" th:value="${profile}" />
与 <input type="radio" th:field="*{skypeProfile}" th:value="${skypeProfile}" />
推荐阅读
- r - 有没有使用条件过滤和删除单个行的好方法?
- r - 计算 1 df 中的坐标向量与其他 df 中的单个坐标之间的距离
- php - Laravel:仅获取特定路由的属性访问器
- serverless-framework - 在 lambda@edge 上使用Sharp
- python - Fractional Max-Pooling:我发现难以实现的深度神经网络
- android - 如何解决返回 null 的 DefaultTrackSelector#getCurrentMappedTrackInfo?
- iframe - 防止在 iframe 中单击鼠标右键
- javascript - 量角器不断耗尽内存
- istio - 使用授权策略将 Istio Ingress Gateway 配置为需要标头令牌
- python - 如何通过跳过字母和^ char将字符串拆分为列表