Thymeleaf 形式th:object和th:each对象在这里使用,它是控制器。
但是发生了运行时错误。我认为这是因为这里使用了 2 个对象。一个是th:object和th:each object
但我想列出所有项目并同时更新成绩并保存或更新。
<form action="#" th:action="@{/saveStudenttest.html}" th:object="test"> //here shown the runtime error
<table class="table" align="center">
<tr>
<th>Student</th>
<th>Test Name</th>
<th>Correct</th>
<th>Wrong</th>
<th>Not-Attended</th>
<th>Grade</th>
</tr>
<tr th:each=" tr : ${testResult}">
<td th:text="${tr.student.name}">NiL</td>
<td th:text="${tr.test.testName}" >NiL</td>
<td th:text="${tr.correct}">NiL</td>
<td th:text="${tr.wrong}" >NiL</td>
<td th:text="${tr.notAttend}">NiL</td>
<td><select >//this is the listbox but the values in list box is not get
<option value="" th:value="${'Excellent'}" >Excellent</option>
<option value="" th:value="${'Very Good'}" >Very Good</option>
<option value="" th:value="${'Good'}" >Good</option>
<option value="" th:value="${'Need To Improve'}" >Need To Improve</option>
</select></td>
<td><input type="submit" class="btn btn-primary" value="Update" name="update" />
<input type="hidden" name="id" th:field="*{id}"/> </td>
</tr>
</table>
</form>
控制器
@RequestMapping(value = Array("parent/result.html"))
def result(testModel: ModelMap): String = {
println(results)
testModel.addAttribute("testResult", results)
"parent/test-result"
}
@RequestMapping(value = Array("parent/ViewReport.html"))
def viewAssessment(stmodel:ModelMap ): String = {
stmodel.addAttribute("test", new StudentTest)
"parent/assessment-report"
}
@RequestMapping(value = Array("/saveStudenttest.html"), params = Array({ "update" }), method = Array(RequestMethod.GET))
def afterUpdateStudenttest(test: StudentTest,@RequestParam id: Long): String = {
test.setId(id)
studentTestService.saveOrUpadeStudentTest(test)
"redirect:/parent/saveStudenttest.html"
}
这是图像
当按下更新按钮时,列表框项目将保存在字段等级中
现在页面无法正确运行显示运行时错误
错误:
无法解析为表达式:“测试”