需要添加依赖:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>
配置:
@Configuration public class WebMvcConfigurer extends WebMvcConfigurerAdapter { @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { //和页面有关的静态目录都放在项目的static目录下 registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/"); //上传的图片在D盘下的OTA目录下,访问路径如:http://localhost:8080/xxx.jpg } }
浏览器正常访问: