springboot+thymeleaf無後綴訪問static下前端靜態HTML報錯總結

今天使用springboot+thymeleaf訪問前端靜態HTML時候,無論Controller裏怎麼寫,lcalhost:8080/login都無法訪問到static下的HTML頁面,我反覆確定Controller代碼沒問題,於是懷疑可能是配置出問題了。

pom.xml裏

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

application.yml裏

##thymeleaf頁面模板配置
spring:
  mvc:
    view:
      prefix: /
      suffix: .html

 粗看似乎沒有問題,pom.xml配置了,前綴配置了,後綴也配置了。

我乾脆嘗試性的把HTML文件放到thymeleaf文件夾下,結果卻能訪問,我就仔細挨個去翻文檔,最後發現原來application.yml裏決定靜態資源的前綴後綴並不是spring.view.prefix和spring.view.suffix,

而是spring.thymeleaf.prefix和spring.thymeleaf.suffix,這東西不去查,而僅僅看還真看不出來。

改成spring.thymeleaf.prefix就可以成功的無後綴訪問static下的靜態HTML了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章