首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >模板解析过程中出错(模板:"class path resource [ template /hello.html]“

模板解析过程中出错(模板:"class path resource [ template /hello.html]“
EN

Stack Overflow用户
提问于 2021-01-04 13:31:06
回答 1查看 574关注 0票数 0
代码语言:javascript
运行
复制
<!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代码,我得到了错误代码

代码语言:javascript
运行
复制
  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行。

我添加了

代码语言:javascript
运行
复制
xmlns:th="http://thymeleaf.org" 

甚至

代码语言:javascript
运行
复制
xmlns:th="https://www.thymeleaf.org"

以及

代码语言:javascript
运行
复制
xmlns:th="http://www.thymeleaf.org"

以上三种方法都不起作用。

我对java端的控制器做了一些改动,如下所示

代码语言:javascript
运行
复制
    @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";
    }
}

这个错误对我来说是不清楚的,我相信这是我的问题,但是,有时你可能必须从头开始这个项目,才能让事情重新开始。

EN

回答 1

Stack Overflow用户

发布于 2021-01-04 16:40:36

你的代码在我的机器上运行得很好。您忘记将www添加到

代码语言:javascript
运行
复制
 xmlns:th="http://thymeleaf.org"

因此您应该添加以下内容

代码语言:javascript
运行
复制
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65558061

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档