继承WebMvcConfigurerAdapter类,重新类中的方法,可以增加额外的配置
@Configuration public class WebMvcConfig extends WebMvcConfigurerAdapter{ /** * 配置静态访问资源 * @param registry */ @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { //registry.addResourceHandler("/img/**").addResourceLocations("classpath:/static/img/");对项目资源进行访问 registry.addResourceHandler("/img/**").addResourceLocations("file:F:/");//对外部资源进行访问 super.addResourceHandlers(registry); } //页面跳转 @Override public void addViewControllers(ViewControllerRegistry registry) { registry.addViewController("/login").setViewName("login"); } }