java.lang.IllegalStateException:bean名称的BindingResult和普通目标对象都不能作为请求属性使用
这是我的表格java.lang.IllegalStateException:bean名称的BindingResult和普通目标对象都不能作为请求属性使用,java,forms,spring-boot,thymeleaf,Java,Forms,Spring Boot,Thymeleaf,这是我的表格 <!DOCTYPE html> <html lang="en" xmlns:th="http://www.thymeleaf.org"> <head th:replace="header :: head"></head> <body> <div th:replace="header :: head-nav"></div> <div id="wrapper"> <div cl
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="header :: head"></head>
<body>
<div th:replace="header :: head-nav"></div>
<div id="wrapper">
<div class="container-fluid">
<div th:each="catFeatGroup,status : ${catFeatGroupList}" class="form-group">
<label>Position</label><input th:field="$ {catFeatGroupList[__${status.index}__].position}" th:value="${catFeatGroup.position}" />
<label>Name</label> <input name="${catFeatGroupList[__${status.index}__].name}" th:value="${catFeatGroup.name}" />
</div>
<button type="submit" class="btn btn-default">Submit</button>
</div>
</div>
<div th:replace="footer :: foot"></div>
</body>
</html>
我缺少什么表达式
th:field=“${catFeatGroupList[\uu${status.index}.\uu].position}”
正在创建错误
th:field
属性只能在html表单
标记中使用,以访问已定义表单的字段。
th:field
属性生成3个html属性,id
、name
和value
因此,您的代码可以修改为:
<div th:each="catFeatGroup,status : ${catFeatGroupList}" class="form-group">
<label>Position</label>
<input th:id="${'catFeatGroupList'+__${status.index}__+'.position'}" th:name="${'catFeatGroupList['+__${status.index}__+'].position'}" th:value="${catFeatGroup.position}" />
<label>Name</label>
<input th:id="${'catFeatGroupList'+__${status.index}__+'.name'}" th:name="${'catFeatGroupList['+__${status.index}__+'].name'}" th:value="${catFeatGroup.name}" />
</div>
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'catFeatGroupList[0]' available as request attribute
<div th:each="catFeatGroup,status : ${catFeatGroupList}" class="form-group">
<label>Position</label>
<input th:id="${'catFeatGroupList'+__${status.index}__+'.position'}" th:name="${'catFeatGroupList['+__${status.index}__+'].position'}" th:value="${catFeatGroup.position}" />
<label>Name</label>
<input th:id="${'catFeatGroupList'+__${status.index}__+'.name'}" th:name="${'catFeatGroupList['+__${status.index}__+'].name'}" th:value="${catFeatGroup.name}" />
</div>
<form th:object="${modelObject}">
<div th:each="catFeatGroup,status : *{catFeatGroupList}" class="form-group">
<label>Position</label>
<input th:field="*{catFeatGroupList[__${status.index}__].position}" />
<label>Name</label>
<input th:field="*{catFeatGroupList[__${status.index}__].name}" />
</div>
</form>