java 非法状态例外:Bean名称“credential”的BindingResult和普通目标对象都不能用作请求属性

igsr9ssn  于 2023-03-11  发布在  Java
关注(0)|答案(1)|浏览(109)

我有这个thymeleaf模板片段:
<form action="#" method="POST" th:action="@{/credentials}" th:object="${credential}"> <input type="hidden" name="credentialId" th:field="*{credentialId}" id="credential-id"> </form>
和此数据类:
'

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Credential {
    private Integer credentialId;
    private String url;
    private String userName;
    private String key;
    private String password;
    private Integer userid;
}`

由于credentialId属性存在于credential:Credential对象中,我不知道为什么会出现这个错误。
我已经尝试确保我在模板中看到的与我在后端中看到的相对应,我没有观察到任何差异。

qxsslcnc

qxsslcnc1#

  • 我还确保向我的模型添加凭据 *

在您的视图中,您没有使用您说要放在Model对象中的凭据,而是使用了凭据
th:object值必须与控制器中的Model匹配。

相关问题