Spring Boot应用程序whitelabel错误页面

时间:2020-09-16 12:05:21

标签: java spring-boot maven

我的springboot应用程序出现了whitelabel错误页面404。我正在对一组学生进行硬编码,他们应该以名字的名字弹出到页面中。我用模板尝试了不同的方法,但是似乎没有任何效果。我也尝试做/ *端点,但是也没有任何效果。我找不到与此问题相关的问题,可以解决我的问题。这些是不同的类;

控制器;

public class StudentController {

private List<Student> studentList = new ArrayList<>();

@GetMapping("/hello")
public String friendListing(Model model) {
    Student student1 = new Student("Kate", "Cole");
    studentList.add(student1);
    Student student2 = new Student("Dan", "Brown");
    studentList.add(student2);
    Student student3 = new Student("Mike", "Mars");
    studentList.add(student3);
    model.addAttribute("studentList", studentList);
    return "hello";
}}

模型;

public class Student {

private String firstName;
private String lastName;

public Student(String fn, String ln) {
    this.firstName = fn;
    this.lastName = ln;
}

public String getFirstName() {
    return firstName;
}
public void setFirstName(String firstName) {
    this.firstName = firstName;
}
public String getLastName() {
    return lastName;
}
public void setLastName(String lastName) {
    this.lastName = lastName;
}
@Override
public String toString() {
    return firstName + " " + lastName;
}}

然后查看;

<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
    <head>
        <title>Server Programming with Spring Boot</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    </head>
    <body>
        <tr th:each="student: ${studentList}">
        <td  th:text="${student.firstName}"></td>
        </tr>
    </body>
</html>

1 个答案:

答案 0 :(得分:0)

您的主要应用程序类别在哪里?

  • 在控制器类包中使用@ComponentScan批注
  • 控制器类应具有@Controller注释。