11-mvc配置原理

mvc配置原理

在这里插入图片描述

扩展springmvc

package com.kuang.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

//如果我们要扩展springmvc,官方建议我们这样去做!
@Configuration
//@EnableWebMvc 这玩意就是导入了一个类 DelegatingWebMvcConfiguration 加了配置会失效
public class MyMvcConfig implements WebMvcConfigurer {
    //视图跳转
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
//        访问/kuang就会跳到test.html页面
        registry.addViewController("/kuang").setViewName("test");
    }
}

  • 在springboot中,有非常多的xxxx Configuration帮助我们进行扩展配置,只要看见了这个东西,我们就要注意了!

版权声明:本文为xixihaha_coder原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。