希望你能帮助解决这个简单的菜鸟问题。我使用springboot和thymeleaf创建了一个多项选择题。我收到此错误,希望你能帮助我编写控制器方法。 执行处理器' org.thymeleaf.spring4.processor.attr.SpringInputGeneralFieldAttrProcessor' (学习:23) 既不是BindingResult也不是bean名称的明确目标对象' options [0]'可用作请求属性
<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>
模型对象
@Entity
public class LearningStyle {
private int Qid;
private String question;
private String ansA;
private String ansB;
public LearningStyle(int qid, String question, String ansA, String ansB) {
Qid = qid;
this.question = question;
this.ansA = ansA;
this.ansB = ansB;
}
public LearningStyle(){}
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "Qid", nullable = false, updatable = false)
public int getQid() {
return Qid;
}
public void setQid(int qid) {
Qid = qid;
}
public String getQuestion() {
return question;
}
public void setQuestion(String question) {
this.question = question;
}
public String getAnsA() {
return ansA;
}
public void setAnsA(String ansA) {
this.ansA = ansA;
}
public String getAnsB() {
return ansB;
}
public void setAnsB(String ansB) {
this.ansB = ansB;
}
}
控制器
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";
}