springboot目录文件结构介绍与使用

2019-05-08  本文已影响0人  激扬文字

1、目录结构(固定)

src/main/java:存放java代码

src/main/resources目录:子目录static 存放css、js、img是springboot默认加载的目录,子目录templates用于存放静态页面如jsp、html等,

子目录config用于存放配置文件,如app.properties

2、springboot要如何访问以上目录中文件?

引入依赖thymeleaf,在pom.xml中进行配置

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-thymeleaf</artifactId>

</dependency>

3、同个文件加载顺序

META/resources>resources>static>public

4、自定义配置目录

需在application.properties 中添加如下内容,其中最后面加粗为自定义目录,配置后页面才可以进行访问。

spring.resources.static-locations=classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,classpath:/testxxx/

5、以上配置无需通过controller请求,直接请求资源文件即可以访问。

上一篇下一篇

猜你喜欢

热点阅读