使用SpringBoot和JSP获取Whitelabel错误页面

时间:2019-01-29 23:46:06

标签: spring mongodb spring-boot jsp

我正在使用Spring Boot和MongoDB运行JSP。我在JSP中收到此错误,我将其称为welcome.jsp。

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.

Tue Jan 29 15:35:40 PST 2019
There was an unexpected error (type=Not Found, status=404).
No message available

application.properties:

spring.mvc.view.prefix=/WEB-INF/
spring.mvc.view.suffix=.jsp

这是在我的pom.xml中

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>

这在EmployeeController.java中

@RequestMapping("/")
public String welcome(Model model) {
    model.addAttribute("employees", getEmployees());
    return "welcome";
}

@RequestMapping("/getEmployees")
public List<Employee> getEmployees() {
    MongoDatabase db = getDatabase();
    MongoCollection<Document> collection = db.getCollection(COLLECTION);
    Document query = new Document();
    List<Employee> employees = collection.find(query, Employee.class).into(new ArrayList<Employee>());
    return employees;
}

1 个答案:

答案 0 :(得分:0)

感谢Alain Cruz建议我将@RequestMapping()更改为@RequestMapping("welcome")