spring boot(二):整合静态资源访问

版权声明:ApassionBoy https://blog.csdn.net/weixin_43150581/article/details/82909003

在我们开发Web应用的时候,需要引用大量的js、css、图片等静态资源。

默认配置

Spring Boot默认提供静态资源目录位置需置于classpath下,目录名需符合如下规则:

/static

/public

/resources

/META-INF/resources

例如:我们可以在src/main/resources/目录下创建static,在该位置放置一个图片文件。启动程序后,尝试访问http://localhost:8089/m.jpg,如果显示出来,则配置成功。

首先去修改pom.xml文件,加入thymeleaf依赖

<!-- 静态资源访问 -->
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

结构图

配置好启动访问http://localhost:8089/m.jpg

记得点一个赞哦,你的赞是小编成功的第一步

上一篇:springboot第一篇(入门)

下一篇: springboot教程第三篇(整合mysql和JdbcTemplate)

源码下载:https://github.com/APassionMy/github.springboot.actual

猜你喜欢

转载自blog.csdn.net/weixin_43150581/article/details/82909003