SpringMvc给页面一个默认界面
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、效果图
原文地址:https://blog.csdn.net/or77iu_N/article/details/141635950
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!