【发布时间】:2021-12-30 13:22:04
【问题描述】:
我不知道我的视图有什么问题,但它不可能工作,即使 idStudent 设置正确,视图也总是会出错。我不知道是否还有其他方法可以做到这一点,但百里香总是失败
这是错误-> Exception evaluating SpringEL expression: "student.id == {idStudent}" (template: "/content/course/list-course-student" - line 55, col 24)
这是我的控制器
@GetMapping("/list-courses-student")
public String listCoursesByUser(@RequestParam(required = false) int page,Model model) {
User currentUser = userService.findByName(this.currentUser.getUsername());
int numberPages = coursesService.getNumberPages();
List<Course> courses = coursesService.findAllCourses(page,true);
model.addAttribute("coursesDisponibles",courses);
model.addAttribute("numberPages",numberPages);
model.addAttribute("currentPage",page);
model.addAttribute("idStudent",currentUser.getStudent().getId());
return "/content/course/list-course-student";
}
我的看法
<div class="card-body table-responsive p-0">
<table class="table table-hover text-nowrap">
<thead>
<tr>
<th>Profesor</th>
<th>Nombre</th>
<th>Description</th>
<th>Code</th>
<th>Inicio</th>
<th>Final</th>
<th>Acciones</th>
</tr>
</thead>
<tbody>
<th:block th:each="course : ${coursesDisponibles}">
<tr>
<td
th:text="${course.teacher == null} ? 'No Asignado' : ${course.teacher.nombre}"></td>
<td th:text="${course.nombre}"></td>
<td th:text="${course.descripcion}"></td>
<td th:text="${course.code}"></td>
<td
th:text="${#temporals.format(course.inicioDate, 'dd/MM/yyyy')}"></td>
<td
th:text="${#temporals.format(course.finalDate, 'dd/MM/yyyy')}"></td>
<td>
<th:block th:each="student : course.Estudiantes">
<th:block th:if="${student != null}">
<th:block th:if="${student.id == {idStudent}}">
<a class="btn btn-success btn-sm" href="">Añadido</a>
<a class="fas fa-inbox ml-3"
th:href="${'/tareas/list-tareas-student?page=1&course=' + {course.id}}"></a>
</th:block>
</th:block>
<th:block th:unless="${student == null}">
<a
th:classappend="${course.teacher == null} ? 'btn btn-primary btn-sm disabled':'btn btn-primary btn-sm' "
th:href="${'/courses/add?idCourse=' + {course.id} + '&idStudent=' + {idStudent}}">Añadir</a>
</th:block>
</th:block>
</td>
</th:block>
</tr>
</tbody>
</table>
</div>
【问题讨论】:
-
请尝试
${student.id == idStudent}。请注意您如何在表达式中再次使用大括号。 -
还是失败了
Exception evaluating SpringEL expression: "student.id == idStudent" (template: "/content/course/list-course-student" -
整个堆栈轨道会有更多细节。这里没有足够的信息......