之前已经问过这个问题,但我没有解决我的问题而且我得到了一些奇怪的功能.
如果我将index.html文件放在静态目录中,如下所示:
我在浏览器中收到以下错误:
在我的控制台中:
[THYMELEAF][http-nio-8080-exec-3] Exception processing template "login":
Exception parsing document: template="login", line 6 - column 3
2015-08-11 16:09:07.922 ERROR 5756 --- [nio-8080-exec-3] o.a.c.c.C.[.[.[/].
[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet]
in context with path [] threw exception [Request processing failed; nested
exception is org.thymeleaf.exceptions.TemplateInputException: Exception
parsing document: template="login", line 6 - column 3] with root cause
org.xml.sax.SAXParseException: The element type "meta" must be terminated by
the matching end-tag "</meta>".
Run Code Online (Sandbox Code Playgroud)
但是,如果我将index.html文件移动到templates目录中,我的浏览器中会出现以下错误:

我添加了我的视图解析器:
@Controller
@EnableWebMvc
public class WebController extends WebMvcConfigurerAdapter { …Run Code Online (Sandbox Code Playgroud) 我的Spring启动应用程序中有以下项目结构,我想使用Thymeleaf
projectName
-Gradle-Module1(Spring boot module)
-build
-src
-main
-resources
-templates
index.html
build.gradle
-Gradle-Module2
...
build.gradle
...
Run Code Online (Sandbox Code Playgroud)
但是spring-boot找不到我的模板目录并显示警告
Cannot find template location: classpath:/templates/ (please add some templates or check your Thymeleaf configuration)
Run Code Online (Sandbox Code Playgroud)
PS:我正在使用 @EnableAutoConfiguration
在我的控制器代码中,我正在做类似的事情
@Controller
@EnableAutoConfiguration
public class BaseController {
@RequestMapping(value = "/")
public String index() {
return "index.html";
}
}
Run Code Online (Sandbox Code Playgroud)
和index.html文件只打印你好世界.
所以通常它应该看起来src/resources/templates/(我想的是相同的Gradle模块),但不知怎的,它无法找到它.
当我尝试访问时,localhost:8080
我得到以下错误Error resolving template "index.html", template might not exist or might not be accessible by any of the configured Template Resolvers …