SpringBoot系列七、静态资源文件配置
2019-01-19 22:55
369 查看
一、目录介绍:
src/main/java:存放代码
src/main/resources
static:存放静态文件,比如 css、js、image
templates:存放静态页面,比如jsp、html、tpl
config:存放配置文件,application.properties
二、同个文件的加载顺序(静态资源文件)
SpringBoot默认会挨个从META/resource>>resources>>static>>public里面查找是否存在相应的资源,如果有则直接返回。
三、访问不是默认文件下的静态资源文件
引入模版引擎(在pom中添加如下依赖)
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>
在src/main/resources文件下创建html文件夹,在html文件夹下创建index.html文件,要访问index.html文件,需要在application.properties中添加下列配置:
spring.resources.static-locations = classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,classpath:/html/
访问http://localhost:8080/index.html即可。
四、通过controller跳转页面
在templates文件夹下创建测试页面Hello.html,创建controller
HelloController如下:
@Controller public class HelloController { @RequestMapping(value = "/hello") public Object hello(){ return "hello"; } }
页面访问http://localhost:8080/hello即可进入hello.html页面。
相关文章推荐
- Spring Boot 静态资源映射与上传文件路由配置
- SpringBoot 静态资源映射文件配置
- spring-boot 加载本地静态资源文件路径配置
- spring-boot 加载本地静态资源文件路径配置
- spring-boot 加载本地静态资源文件路径配置
- spring-boot 加载本地静态资源文件路径配置
- spring-boot 加载本地静态资源文件路径配置
- SpringBoot系列四:SpringBoot开发(改变环境属性、读取资源文件、Bean 配置、模版渲染、profile 配置)
- spring boot 加载本地静态资源文件路径配置
- spring-boot 加载本地静态资源文件路径配置
- spring-boot 加载本地静态资源文件路径配置
- spring-boot 加载本地静态资源文件路径配置
- spring-boot 加载本地静态资源文件路径配置
- spring-boot 加载本地静态资源文件路径配置
- spring-boot 加载本地静态资源文件路径配置
- Spring Boot干货系列:(二)配置文件解析
- Spring Boot干货系列:(六)静态资源和拦截器处理
- springboot maven打包静态资源文件
- Spring Boot干货系列:(二)配置文件解析
- logback:输出日志到文件(滚动)&& Spring Boot干货系列:(七)默认日志logback配置解析(转载)