问题描述
我想在另一个HTML页面中编辑表格的一行。 我有百里香和Spring MVC的初学者...
profilesAll.html
但是,我有这个错误: org.thymeleaf.exceptions.TemplateProcessingException:执行处理器'org.thymeleaf.Spring5.processor.SpringInpuTradioFieldTagProcessor'时出错(模板:“ profilsAll”-第39行,第26行) ....
原因:java.lang.IllegalStateException:Bean名称为'profil'的BindingResult或普通目标对象都不能用作请求属性
ProfilsAll.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}" />