最简洁方式:使用API
在配置文件下写配置类SpringMvcSupport,并且让SpringMVC扫描到此文件夹@ComponentScan({"com.itheima.controller","com.itheima.config"})
SpringMvcSupport配置类如下
@Configuration
public class SpringMvcSupport extends WebMvcConfigurationSupport {@Overrideprotected void addResourceHandlers(ResourceHandlerRegistry registry) {registry.addResourceHandler("/pages/**").addResourceLocations("/pages/");registry.addResourceHandler("/css/**").addResourceLocations("/css/");registry.addResourceHandler("/js/**").addResourceLocations("/js/");registry.addResourceHandler("/plugins/**").addResourceLocations("/plugins/");}
}
步骤:
1、在config文件下写SpringMvcConfig配置类
2、在SpringMvcConfig也就是SpringMVC核心配置类中扫描到此文件夹,那么此配置类就会被扫描到
SpringMvcConfig类如下:
@Configuration
@ComponentScan({"com.itheima.controller","com.itheima.config"})
@EnableWebMvc
public class SpringMvcConfig {
}
如果不行,重启啥的。代码肯定是没错的。