简体   繁体   English

SPRING - 我得到的是 Whitelabel 错误页面而不是我的家,为什么?

[英]SPRING - I get the Whitelabel Error Page instead of my home, why?

Good morning,早上好,

I'm trying to write a simple web app with Spring and MVC, in the console it's all good but when I try to get the home page from the url the browser gives me the Whitelabel Error Page with error 404.我正在尝试使用 Spring 和 MVC 编写一个简单的 web 应用程序,在控制台中一切都很好,但是当我尝试从 Z572D4E421E5E6B9BC11D804E8A027112 获取主页时,浏览器给出了错误的白色页面。

This is my controller:这是我的 controller:

package com.beanspring.controller;



import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;

import org.springframework.ui.Model;

import org.springframework.web.bind.annotation.PathVariable;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;



import com.beanspring.model.Alimento;

import com.beanspring.model.GiornoDiDieta;

import com.beanspring.service.alimentoService;

import com.beanspring.service.giornoDiDietaService;





u/Controller

u/RequestMapping(value ="/dieta")



public class DietaController {

u/Autowired

alimentoService alService;



u/Autowired

giornoDiDietaService giornoService;



u/RequestMapping(value ="/home", method = RequestMethod.GET )

public String creaHome(Model model) 

{



    model.addAttribute("listaAlimenti", alService.getAllAlimenti());

    System.out.println("ECCOMI");

    return "Home";

}


}

Home.html is in src/main/resources/templates and it shows as I expect in a browser if I open it directly. Home.html 位于 src/main/resources/templates 中,如果我直接打开它,它会在浏览器中显示。

The Spring console shows no error and it even prints "ECCOMI", so the url "localhost:8080/dieta/home" gets the method. Spring 控制台没有显示错误,它甚至打印“ECCOMI”,因此 url “localhost:8080/dieta/home” 获取该方法。

This is my file POM, I feel the error is in there.这是我的文件 POM,我觉得那里有错误。

   <?xml version="1.0" encoding="UTF-8"?>
    
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    
    xsi:schemaLocation="[http://maven.apache.org/POM/4.0.0](http://maven.apache.org/POM/4.0.0) [https://maven.apache.org/xsd/maven-4.0.0.xsd](https://maven.apache.org/xsd/maven-4.0.0.xsd)">
    
    <modelVersion>4.0.0</modelVersion>
    
    <parent>
    
        <groupId>org.springframework.boot</groupId>
    
        <artifactId>spring-boot-starter-parent</artifactId>
    
        <version>2.5.0</version>
    
        <relativePath/> <!-- lookup parent from repository -->
    
    </parent>
    
    <groupId>com.slide</groupId>
    
    <artifactId>dieta-2</artifactId>
    
    <version>0.0.1-SNAPSHOT</version>
    
    <name>dieta-2</name>
    
    <description>Demo project for Spring Boot</description>
    
    <properties>
    
        <java.version>16</java.version>
    
    </properties>
    
    <dependencies>
    
        <dependency>
    
            <groupId>org.springframework.boot</groupId>
    
            <artifactId>spring-boot-starter-data-jdbc</artifactId>
    
        </dependency>
    
        <dependency>
    
            <groupId>org.springframework.boot</groupId>
    
            <artifactId>spring-boot-starter-data-jpa</artifactId>
    
        </dependency>
    
        <dependency>
    
            <groupId>org.springframework.boot</groupId>
    
            <artifactId>spring-boot-starter-web</artifactId>
    
        </dependency>
    
    
        <dependency>
    
            <groupId>mysql</groupId>
    
            <artifactId>mysql-connector-java</artifactId>
    
            <scope>runtime</scope>
    
        </dependency>
    
        <dependency>
    
            <groupId>org.mariadb.jdbc</groupId>
    
            <artifactId>mariadb-java-client</artifactId>
    
            <scope>runtime</scope>
    
        </dependency>
    
        <dependency>
    
            <groupId>org.springframework.boot</groupId>
    
            <artifactId>spring-boot-starter-test</artifactId>
    
            <scope>test</scope>
    
        </dependency>
    
    </dependencies>
    
    
    <build>
    
        <plugins>
    
            <plugin>
    <groupId>org.springframework.boot</groupId>
    
    <artifactId>spring-boot-maven-plugin</artifactId>
    
            </plugin>
    
        </plugins>
    
    </build>
    
    
    </project>

Will you help me, please?请你帮帮我好吗?

LOL I had forgot Thymeleaf.哈哈,我忘了 Thymeleaf。 I've added我已经添加

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

and now it works!现在它可以工作了!

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

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