zoukankan      html  css  js  c++  java
  • 扩展与全面接管springmvc

    1.新建MyMvcconfig配置类,来扩展spingmvc

    @Configuration
    public class MyMvcConfig extends WebMvcConfigurerAdapter {
        @Override
        public void addViewControllers(ViewControllerRegistry registry) {
                registry.addViewController("/").setViewName("success"); //浏览器发送请求来到success页面
        }
    }

    该类的类型是WebMvcConfigurerAdapter(继承),使用WebMvcConfigurerAdapter可以扩展,不能标注@EnableWebMvc;既保留了配置,也能拓展我们自己的应用。

    原理:

    1)、WebMvcAutoConfiguration是SpringMVC的自动配置

    2)、在做其他自动配置时会导入;@Import(EnableWebMvcConfiguration.class)

     3)、自己的配置被调用

    效果:SpringMVC的自动配置和我们的扩展配置都会起作用

    2.若想全面接管springmvc使用@EnableWebMvc注解

    @EnableWebMvc
    @Configuration
    public class MyMvcConfig extends WebMvcConfigurerAdapter {
        @Override
        public void addViewControllers(ViewControllerRegistry registry) {
                registry.addViewController("/").setViewName("success"); //浏览器发送请求来到success页面
        }
    }
  • 相关阅读:
    桂林印象
    快变
    近期的事
    *C#中使用ref和out一点认识!*
    *在框架集页面放置TreeView控件时页面跳转的问题解决*
    *无法找到脚本库的问题*
    *Ajax.Net快速入门*
    *网页过期*
    *Prototype开发笔记*
    *正则表达式*
  • 原文地址:https://www.cnblogs.com/menbo/p/11045648.html
Copyright © 2011-2022 走看看