Spring Boot - 访问静态资源

mac2022-06-30  26

首先要添加依赖

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

Spring Boot访问静态资源是由一定规则的,那就是放静态资源的目录需要在classpath(src/main/resources/)下,目录名要符合如下几个:

staticpublicresourcesMETA-INF/resources

 这边以static举例,在static放入一张图片1.png

访问的时候需要注意,我们直接访问文件名就行,不需要加/static之类的前缀,如下图,直接访问http://localhost:8080/1.png

 

最新回复(0)