wangsr-suc

摘要:在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");
    }
}

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

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

 

posted on 2018-05-27 16:30 suc-浮生 阅读(...) 评论(...) 编辑 收藏

相关文章:

  • 2021-09-04
  • 2021-12-19
  • 2022-01-20
  • 2021-12-13
  • 2021-04-20
  • 2021-08-28
猜你喜欢
  • 2021-05-04
  • 2021-12-11
  • 2021-06-28
  • 2021-12-21
  • 2021-04-09
  • 2021-06-20
  • 2021-12-19
  • 2021-10-15
相关资源
相似解决方案