zoukankan      html  css  js  c++  java
  • SpringBoot---页面跳转之WebMvcConfigurerAdapter

    摘要:在springboot中定义自己的方法继承WebMvcConfigurerAdapter方法可以实现扩展springMvc功能,要全面实现接管springmvc就要在自己的方法上加上@EnableWebMvc注解。

    • 首先看WebMvcConfigurerAdapter部分源码:
      @Deprecated//看标色部分就是实现了WebMvcConfigurer接口  因此可以理解为什么说扩展springmvc功能
      public abstract class WebMvcConfigurerAdapter implements WebMvcConfigurer {
      
          /**
           * {@inheritDoc}
           * <p>This implementation is empty.
           */
          @Override
          public void configurePathMatch(PathMatchConfigurer configurer) {
          }
      
          /**
           * {@inheritDoc}
           * <p>This implementation is empty.
           */
      ......
    • 如何实现页面跳转(实质就是配置结果视图)
    @Configuration
    public class MyMvcConfig extends WebMvcConfigurerAdapter {
        @Override
        public void addViewControllers(ViewControllerRegistry registry) {
            registry.addViewController("/cn.itcast").setViewName("login");
        }
    }

    //第二种方法:
    @Bean
        public WebMvcConfigurerAdapter webMvcConfigurerAdapter() {
            WebMvcConfigurerAdapter adapter=new WebMvcConfigurerAdapter() {
    
                @Override
                public void addViewControllers(ViewControllerRegistry registry) {
                    registry.addViewController("/cn.itcast").setViewName("login");
                }
            };
            return adapter; 
        }
    
    
    




    其中addViewController方法可设置映射路径 / 代表当前项目,后面的自定义,setViewName设置要被映射的html文件

    注意:此文件需要在resourse包下的template文件夹下,不然没法找到访问异常如下:

  • 相关阅读:
    phonegap_android配置文档
    JQueryMobile + PhoneGap 经验总结
    nand ECC 算法记录
    u-boot 2016.05 添加自己的board 以及config.h
    git commit 多行注释方法说明
    Ubuntu 下新建用户后无法sudo
    QT4.8.5 QComboBox 增加选择菜单记录
    Linux GPIO控制方法
    Qt5 can't find -LGL
    windows 端搭建nfs 服务器
  • 原文地址:https://www.cnblogs.com/wangsr-suc/p/9096431.html
Copyright © 2011-2022 走看看