【发布时间】:2023-01-02 22:40:54
【问题描述】:
所以,我写了 spring boot Controller,写了 Entity -> Course,写了 html views-> courses,但是我的信息没有在我的模板中查看。
@Controller
@RequestMapping ("/courses")
public class CourseController {
private CourseService courseService;
public CourseController(CourseService courseService) {
this.courseService = courseService;
}
@GetMapping ("/index")
public String getCourses (Model model, @RequestParam (name="keyword", defaultValue = "") String keyword ) {
List <Course> courses = courseService.findCourseBycourseName(keyword);
model.addAttribute("listCourses", courses);
model.addAttribute("keyword", keyword);
return "views/courses";
}
HTML + Thymeleaf courses.html -> 当我启动应用程序时只加载空表。
<tbody>
<tr class ="text-center" th:each="course : ${listCourses}" >
<td th:text = "${course.getCourseId()}"> </td>
<td th:text = "${course.getCourseName()}"> </td>
<td th:text = "${course.getCourseDuration()}"> </td>
<td th:text = "${course.getCourseDescription()}"> </td>
<td th:text = "${course.getInstructor().getInstructorFirstName()} + '' + course.getInstructor().getInstructorLastName"> </td>
<td th:text = "${course.getListStudent().size()}"> </td>
</tbody>
</table>
谁知道哪里有问题
【问题讨论】:
-
courseService.findCourseBycourseName()方法有返回值吗?如果courses列表有项目,也许用调试器检查一下?
标签: spring-boot thymeleaf