1. 前言
这几天做一个小项目,碰到了一些奇葩bug,各种百度都无法解决,只有自己一个一个试,气到爆炸。springboot中静态页面templates下的HTML文件无法直接访问,还有就是return "redirect:”无法重定向问题,这篇博客就解决这个坑。
2. 静态页面无法加载
先看看我的项目目录架构:
templates下的静态页面根本无法通过localhost:8080/ 访问
原因是啥呢?
静态资源加载顺序顺序
静态资源路径默认配置:
spring.resources.static-locations = classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/
复制代码
静态页面spring boot根本没有加载,导致无法直接访问。
怎么解决?
很简单,修改加载路径,加上templates就行了。
yml配置如下
spring:
resources:
static-locations: classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,classpath:/templates/
复制代码xml配置
spring.resources.static-locations = classpath: /META-INF/resources/,classpath: