1、Controller
@Controller
public class TestController {
@RequestMapping("/test")
public String test(){
return "index";
}
}
2、templates/index.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>wit</title>
</head>
<body>
<p>hello,SpringBoot</p>
</body>
</html>
3、在浏览器访问
http://localhost:8080/test
报错
org.thymeleaf.exceptions.TemplateInputException: Error resolving template [index1], template might not exist or might not be accessible by any of the configured Template Resolvers
4、问题所在
之前为了将mapper下的XXXMapper.xml打包发布,在pom.xml文件中加入了如下,但并没有把html模板打包,在如下中加入注释的代码即可。
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
<include>**/*.yaml</include>
<!--<include>**/*.html</include>-->
</includes>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
<include>**/*.yaml</include>
<!--<include>**/*.html</include>-->
</includes>
<filtering>true</filtering>
</resource>
</resources>