idea創建springboot項目無法訪問html文件


 

首先說明,不需要在此處做任何配置:

 

 

1、引入thmeleaf模板引擎

<!-- thmeleaf模板引擎 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

2、配置application.properties 如下:

spring.thymeleaf.mode=HTML5
spring.thymeleaf.cache=false
spring.thymeleaf.encoding=utf-8
spring.thymeleaf.prefix=classpath:/templates/views/   #該路徑自己指定
spring.thymeleaf.suffix=.html

3、html頁面放到resources/templates下(可以自己在下面創建包,但要在prefix中指定,或者在controller中配置)

* idea創建的html頁面,<meta>標簽不是閉合的,需要添加</meta>,感覺thmeleaf太死板,容錯率太低

4、controller中如下:

 

 OK,到這里啟動springboot就可以了


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM