我正在使用Thymeleaf的Spring Boot,并试图访问一个简单的网页。 构建项目时我没有任何错误。仅这一项访问localhost:8080/greeting
时:使用Spring Boot/Thymeleaf的“无消息”
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Fri Dec 02 15:36:04 CET 2016
There was an unexpected error (type=Not Found, status=404).
No message available
我有一个控制器:
package controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@Controller
public class UserController {
@RequestMapping("/greeting")
public String user(@RequestParam(value = "name", required = false, defaultValue = "World") String name, Model model){
model.addAttribute("name",name);
return "greeting";
}
}
主:
package boot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main (String[] args){
SpringApplication.run(Application.class, args);
}
}
和网页:
<!DOCTYPE html>
<html xmlns:th="http://www.themyleaf.org">
<head>
<meta charset="ISO-8859-1"/>
<title>SecondMaven</title>
</head>
<body>
<p th:text="'Hello, '+ ${name} + '!!!!!'" />
</body>
</html>
我pom.xml
:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
我对代码有什么问题没有任何线索。我认为这是一个配置问题,但到目前为止,我没有得到任何运气。 我将不胜感激任何帮助,谢谢。
你在哪里把你的'greeting.html'? –
在src/main/resources/templates中。 – Chuck