5.springboot目录结构
2020-03-19 本文已影响0人
0f701952a44b
1.目录说明:
11.jpgsrc/main/java:存放代码
src/main/resources
static: 存放静态文件,比如 css、js、image, (访问方式 http://localhost:8080/js/main.js)
templates:存放静态页面jsp,html,tpl
config:存放配置文件,application.properties
2.访问静态页面
1)将index.html放入templates文件夹下
2)引入依赖
<!-- 使用Thymeleaf视图构建MVC Web应用程序的入门 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
3)创建controller
@Controller
public class HtmlTestController {
@GetMapping("/v1/testhtml")
public Object testhtml() {
return "index";
}
}
4)使用http://localhost:8080/v1/testhtml即可访问
注意:如果不引人这个依赖包,html文件应该放在默认加载文件夹里面(例如:resources、static、public这个几个文件夹,才可以访问)
3.同一个文件的加载顺序,
静态资源文件 Spring Boot 默认会挨个从
META/resources >
resources >
static >
public
里面找是否存在相应的资源,如果有则直接返回,都没有则报错。
4.springboot默认从resources、static、public查找静态文件,如果要指定这几个之外的查找。则需在application.properties文件中指定
#在后面添加需要指定的路径
spring.resources.static-locations = classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/