Thymeleaf形式 th:object 和 th:每个对象在这里使用,它是控制器。
但是发生了运行时错误。我认为这是因为在这里使用了2个对象。一个是 th:object 和 th:每个对象
但我想列出所有项目,同时更新成绩和保存或更新。
<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"
}
这是图像
按下更新按钮时,列表框项目将保存在成绩
字段中现在页面运行不正确显示运行时错误
错误:
无法解析为表达式:“test”
答案 0 :(得分:1)
试试这个..这里select的值传递给控制器
<form action="#" th:action="@{/saveStudenttest.html}" >
<table class="table" align="center">
<tr>
<th>Student</th>
<th>Test Name</th>
<th>Correct</th>
<th>Wrong</th>
<th>Not-Attended</th>
<th>Assign Grade</th>
<!-- <th>Max-Mark</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 name ="combo">
<option value="Excellent" th:value="${'Excellent'}">Excellent</option>
<option value="Very Good" th:value="${'Very Good'}" >Very Good</option>
<option value="Good" th:value="${'Good'}" >Good</option>
<option value="Need to Improove" 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:value="${tr.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", results)
"parent/assessment-report"
}
@RequestMapping(value = Array("/saveStudenttest.html"), params = Array({ "update" }), method = Array(RequestMethod.GET))
def afterUpdateStudenttest(test: StudentTest,@RequestParam id: Long,combo:String): String = {
var tId:StudentTest=studentTestService.findStudentTestById(id)
println(tId+"#####################"+combo)
tId.setGrade(combo)
studentTestService.saveOrUpadeStudentTest(tId)
"redirect:/parent/ViewReport.html"
}