zoukankan      html  css  js  c++  java
  • springboot配置视图控制器

    实现WebMvcConfigurer接口
    /**
    * @descripte 配置自己的视图解析器
    */
    @Configuration
    public class MyViewConfigController implements WebMvcConfigurer {


    @Override
    /*重写addViewControllers实现*/
    public void addViewControllers(ViewControllerRegistry registry) {
    registry.addViewController("/123").setViewName("index");
    }
    }

    继承WebMvcConfigurationSupport类
    /**
    * @descripte 配置自己的视图解析器
    */
    @Configuration
    public class MyViewConfigController extends
    WebMvcConfigurationSupport{
        @Override
    /*重写addViewControllers实现*/
    public void addViewControllers(ViewControllerRegistry registry) {
    registry.addViewController("/123").setViewName("index");
    }
    }

    这两种最大区别是实现
    WebMvcConfigurer可以使用springmvc自动配置,
    继承
    WebMvcConfigurationSupport
    可以使用springmvc自动配置
    例如静态资源不能访问
    (/static),原因如下:
    @Configuration
    @ConditionalOnWebApplication(type = Type.SERVLET)
    @ConditionalOnClass({ Servlet.class, DispatcherServlet.class, WebMvcConfigurer.class })
    @ConditionalOnMissingBean(WebMvcConfigurationSupport.class)//如果没有WebMvcConfigurationSupport,才自动使用springmvc配置
    @AutoConfigureOrder(Ordered.HIGHEST_PRECEDENCE + 10)
    @AutoConfigureAfter({ DispatcherServletAutoConfiguration.class,
          ValidationAutoConfiguration.class })
    public class WebMvcAutoConfiguration {
    
    
    继承WebMvcConfigurationSupport,就相当于在容器中添加这个类了。
     
     
     
  • 相关阅读:
    PTA(Basic Level)1012.数字分类
    PTA(Basic Level)1011.A+B和C
    PTA(Basic Level)1008.数组元素循环右移问题
    PTA(Basic Level)1009.说反话
    PTA(Basic Level)1010.一元多项式求导
    Leetcode 38.报数 By Python
    Leetcode 35.搜索插入位置 By Python
    查看Linux的所有线程
    Linux内核模块编程——Hello World模块
    JSP内置对象总结
  • 原文地址:https://www.cnblogs.com/metu/p/9251649.html
Copyright © 2011-2022 走看看