【发布时间】:2021-06-24 07:21:47
【问题描述】:
我知道 stackoverflow 中有一个类似的问题,就像我的一样。我尝试了这个问题的所有答案,但这些都不起作用:Thymeleaf using path variables to th:href
你能帮我在百里香页面上做错什么吗? 我想访问的 URL:localhost:8081/students/{stu_id}
我的 GetMapping 看起来像:
@GetMapping("/students")
public ModelAndView viewStudentPage() {
List<Student_Dim> listStudent = studentService.getAllStudents();
return new ModelAndView("students","students", listStudent);
}
@GetMapping("/students/{id}")
private ModelAndView getInfo(@PathVariable("id") String stu_id){
Student_Dim student = studentService.getStudentById(stu_id);
return new ModelAndView("student","student",student);
}
我使用的 Href (students.html):
<tbody>
<tr th:each="student : ${students}">
<td th:text="${student.stu_fname}">First Name</td>
<td th:text="${student.stu_lname}">Last Name</td>
<td th:text="${student.dep_code}">Department Code</td>
<td th:text="${student.fac_code}">Faculty Code</td>
<td th:text="${student.loc_code}">Location Code</td>
<td th:text="${student.marriage_status}">Marriage Status</td>
<td th:text="${student.address}">Address</td>
<td>
<a href="@{/students/{id}(id=${student.stu_id})}">Edit</a>
</td>
</tr>
</tbody>
【问题讨论】:
-
定义:不工作(ing)?会发生什么?
-
有什么问题?顺便说一句,我看到在 java 代码中,您在模型中添加了一个
student,而在模板代码中,您使用的是学生列表students,所以它无法工作 -
我有两个不同的页面,一个用于列出所有学生,一个用于编辑特定学生。我想从students.html 访问student.html。我编辑了我的问题。 @OlivierBoissé
标签: java spring spring-boot thymeleaf