繁体   English   中英

Spring Boot 应用程序白标错误页面

[英]Spring boot application whitelabel error page

我的 springboot 应用程序出现白标错误页面 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>

你的主要应用类在哪里?

  • @ComponentScan注释与您的控制器类包一起使用
  • 控制器类应该有@Controller注释。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM