Ich verwende und die thymeleaf
View-Engine.Warum wird die HTML-Seite nicht in Thymole angezeigt?
Das Problem ist der Controller zeigt nicht die richtige HTML-Seite und zeigt immer die Whitelabel Error Page
.
Der Controller:
package com.example.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class GifController {
@RequestMapping("/greeting")
public String sayhello() {
return "greets";
}
}
Die greets.html Datei in Ressourcen/templates Pfad:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<title>Insert title here</title>
</head>
<body>
Hello!
</body>
</html>
auch:
@EnableAutoConfiguration
@SpringBootApplication
@ComponentScan
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
Und die pom.xml:
<?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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Wo ist das Problem? Wenn ich zu localhost:8080/greeting
blättern, zeigt es whitelabel Error page
anstelle der greets.html
.
Alles ist in Ordnung, aber es funktioniert nicht ... –
Ich habe Ihren Code getestet und es funktioniert für mich. Versuchen Sie index.html im Template-Ordner hinzuzufügen und eine weitere Methode in GifController wie @RequestMapping ("/") public String hallo() { return "index"; }. Versuchen Sie zu säubern, verpacken Sie Ihr Projekt und testen Sie es. – abaghel