在使用WebConfig中出现No mapping for GET的问题
原因:
拦截器拦截路径问题
解决办法:
加入下面代码
//解决 No mapping for GET /favicon.ico 访问静态资源图标
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**")
.addResourceLocations("classpath:/static/")
.addResourceLocations("classpath:/META-INF/resources/");
}
下面的是完整的WebConfig
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.util.List;
@Configuration
@EnableWebMvc
public class WebConfig implements WebMvcConfigurer {
@Autowired
private UserArgumentResolve userArgumentResolve;
//解决 No mapping for GET /favicon.ico 访问静态资源图标
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**")
.addResourceLocations("classpath:/static/")
.addResourceLocations("classpath:/META-INF/resources/");
}
// 该方法可以用于Controller中方法参数传入之前对该参数进行处理,然后将处理好的参数传给Controller中的方法
@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
// userArgumentResolve类对Controller传入的参数做了处理
resolvers.add(userArgumentResolve);
}
}