0

Thymeleaf 形式th:objectth:each对象在这里使用,它是控制器

但是发生了运行时错误。我认为这是因为这里使用了 2 个对象。一个是th:objectth: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"
    }

这是图像

在此处输入图像描述

当按下更新按钮时,列表框项目将保存在字段等级中

现在页面无法正确运行显示运行时错误

错误:

无法解析为表达式:“测试”

4

1 回答 1

1

试试这个..这里选择的值是传递给控制器

 <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"
  }
于 2013-08-17T08:56:01.423 回答