解决 No mapping for GET /静态资源 请访问我下一个博客
https://blog.csdn.net/qq_41835813/article/details/105382341
package com.springbootdemo.cgf;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
/**
* @author qyc
* @time 2020/4/5 - 4:08
*/
@Configuration
public class Config extends WebMvcConfigurationSupport {
@Override //页面跳转
protected void addViewControllers(ViewControllerRegistry registry) {
// super.addViewControllers(registry);
// registry.addViewController("/test03").setViewName("succ");
registry.addViewController("/").setViewName("index");
registry.addViewController("/login").setViewName("login");
}
// 解决 No mapping for GET /webjars/bootstrap
private static final String[] CLASSPATH_RESOURCE_LOCATIONS = {
"classpath:/META-INF/resources/", "classpath:/resources/",
"classpath:/static/", "classpath:/public/" };
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
if (!registry.hasMappingForPattern("/webjars/**")) {
registry.addResourceHandler("/webjars/**").addResourceLocations(
"classpath:/META-INF/resources/webjars/");
}
if (!registry.hasMappingForPattern("/**")) {
registry.addResourceHandler("/**").addResourceLocations(
CLASSPATH_RESOURCE_LOCATIONS);
}
}
}