虽然我将@Controller更改为@RestContoller,但它打印的不是index.html而是“index”
它应该将 html 文件放入模板文件夹中,但它不起作用
我还尝试添加一些属性
spring.thymeleaf.prefix=/templates
spring.thymeleaf.suffix=.html
在 application.properties 中,它仍然不起作用
提前感谢您的帮助
确保你的pom包含thymeleaf依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
将模板放在
src/main/resources/templates
文件夹下。默认扩展名是 .html
确保您的控制器有
@RequestMapping
注释
@Controller
@RequestMapping("/")
class MainController {
@GetMapping
public String viewHomePage() {
return "index";
}
}
从
application.properties
删除所有配置