添加静态文件
第一种,使用property文件
| 12
 
 | spring.mvc.static-path-pattern=/static
 
 | 
第二种,使用自定义
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 
 |  
 import org.springframework.stereotype.Component;
 import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
 import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
 
 
 
 
 @Component
 public class MyWebMvcConfig implements WebMvcConfigurer {
 @Override
 public void addResourceHandlers(ResourceHandlerRegistry registry) {
 registry.addResourceHandler("/static/**")
 .addResourceLocations("classpath:/static/");
 }
 }
 
 | 
输入http://localhost:8080/static/java.png就可以访问了