Spring boot Springboot和thymealf循环
希望你能帮助解决这个简单的noob问题。我使用springboot和thymeleaf创建了一个选择题。我得到了这个错误,希望您能帮助我编写控制器方法。 执行处理器“org.thymeleaf.spring4.processor.attr.springInputGeneralFieldDattrProcessor”时出错(学习:23) bean名称“选项[0]”的BindingResult和普通目标对象都不能作为请求属性使用Spring boot Springboot和thymealf循环,spring-boot,thymeleaf,Spring Boot,Thymeleaf,希望你能帮助解决这个简单的noob问题。我使用springboot和thymeleaf创建了一个选择题。我得到了这个错误,希望您能帮助我编写控制器方法。 执行处理器“org.thymeleaf.spring4.processor.attr.springInputGeneralFieldDattrProcessor”时出错(学习:23) bean名称“选项[0]”的BindingResult和普通目标对象都不能作为请求属性使用 <form method="post" th:action="
<form method="post" th:action="@{/list}" >
<table>
<tr th:each="option, rowStat : *{a}">
<td><input type="radio" th:field="*{options[__${rowStat.index}__].ansA}" th:value="A"/></td>
<td><input type="radio" th:field="*{options[__${rowStat.index}__].ansB}" th:value="B"/></td>
</tr>
</table>
<input type="submit" value="ok"/>
</form>
}
控制器
public class LearningStyleController {
@Autowired
LearningStyleService learningstyleservice;
@RequestMapping("/list")
public String learningstyle(Model model) {
List<LearningStyle> a= learningstyleservice.findAll();
model.addAttribute("a",a);
return "learning";
}
@RequestMapping(value = "/list", method = RequestMethod.POST)
public String learn(@ModelAttribute("a") LearningStyle learningStyle, Model model) {
//code to get list of object
return "home";
}
公共类LearningStyleController{
@自动连线
LearningStyleService LearningStyleService;
@请求映射(“/list”)
公共字符串学习样式(模型){
列表a=learningstyleservice.findAll();
model.addAttribute(“a”,a);
回归“学习”;
}
@RequestMapping(value=“/list”,method=RequestMethod.POST)
公共字符串学习(@modeldattribute(“a”)LearningStyle LearningStyle,Model Model){
//获取对象列表的代码
返回“家”;
}
我尝试此操作,但错误消失,但我的th:name在此出错!!!th:name设置在哪里?有什么错误?
public class LearningStyleController {
@Autowired
LearningStyleService learningstyleservice;
@RequestMapping("/list")
public String learningstyle(Model model) {
List<LearningStyle> a= learningstyleservice.findAll();
model.addAttribute("a",a);
return "learning";
}
@RequestMapping(value = "/list", method = RequestMethod.POST)
public String learn(@ModelAttribute("a") LearningStyle learningStyle, Model model) {
//code to get list of object
return "home";
}