1、config包
1.1、创建SpringMvcConfig类并实现接口WebMvcConfigurer
@EnableWebMvc
public class SpringMvcConfig implements WebMvcConfigurer {
//视图解析器
@Bean
public ViewResolver viewResolver() {
InternalResourceViewResolver viewResolver =
new InternalResourceViewResolver();
viewResolver.setPrefix("/WEB-INF/views/");
viewResolver.setSuffix(".jsp");
return viewResolver;
}
//配置WebMvc相关配置,实现接口 WebMvcConfigurer
//视图控制,默认首页
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("index");
}
}
1.2、AppConfig类
@Configuration
@ComponentScan("")
@Import({SpringMvcConfig.class})
public class AppConfig {
}
2、效果图