<!DOCTYPE html>
<html lang="en"
xmlns:th="http://www.w3.org/1999/xhtml"
xmlns:th="http://thymeleaf.org">
<head>
<title>Hello Spring Boot</title>
</head>
<body>
<h2 th:text="${message}"></h2>
<h1>Welcome to Spring Boot with Intellij IDEA</h1>
</body>
</html>
上面是我的HTML代码,我得到了错误代码
Mon Jan 04 00:24:01 EST 2021
There was an unexpected error (type=Internal Server Error, status=500).
An error happened during template parsing (template: "class path resource [templates/hello.html]" - line 4, col 7)
org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/hello.html]" - line 4, col 7)
at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:239)``
这些是我尝试过的解决方案。
我没有费心去放那些不重要的部分,它们是给我带来错误的前3行。
我添加了
xmlns:th="http://thymeleaf.org"
甚至
xmlns:th="https://www.thymeleaf.org"
以及
xmlns:th="http://www.thymeleaf.org"
以上三种方法都不起作用。
我对java端的控制器做了一些改动,如下所示
@Controller
public class WebController {
@GetMapping("/hello")
public String sayHello(HttpServletRequest request){
System.out.println("Saying hello world Spring Boot....");
request.setAttribute("message", "Greetings");
return "hello";
}
}
这个错误对我来说是不清楚的,我相信这是我的问题,但是,有时你可能必须从头开始这个项目,才能让事情重新开始。
发布于 2021-01-04 16:40:36
你的代码在我的机器上运行得很好。您忘记将www添加到
xmlns:th="http://thymeleaf.org"
因此您应该添加以下内容
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
https://stackoverflow.com/questions/65558061
复制相似问题