SpringBoot:扩展SpringMVC

If you want to keep those Spring Boot MVC customizations and make more MVC customizations (interceptors, formatters, view controllers, and other features), you can add your own @Configuration class of type WebMvcConfigurer but without @EnableWebMvc.

编写一个配置类,添加@Configuration注解,但不能标注@EnableWebMvc注解,实现WebMvcConfigurer接口,通过实现接口中定义的方法实现扩展springmvc的功能。

@Configuration
public class MyMvcConfig implements WebMvcConfigurer {
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("login");
        registry.addViewController("/login").setViewName("login");
        registry.addViewController("/index").setViewName("login");
        registry.addViewController("/login.html").setViewName("login");
        registry.addViewController("/index.html").setViewName("login");
    }
    
}
posted @ 2021-12-30 10:12  amo丶k  阅读(41)  评论(0编辑  收藏  举报