Spring Boot笔记七:扩展Spring MVC

新建一个类,继承WebMvcConfigurerAdapter

package com.vae.springboot.config;

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

//使用WebMvcAutoConfigurationAdapter可以扩展SpringMVC的功能
@Configuration
public class MyMVCConfig extends WebMvcConfigurerAdapter {

    public void addViewControllers(ViewControllerRegistry registry){
        registry.addViewController("/shuyunquan").setViewName("Vae");
    }

}

注意addViewControllers这个方法是重写的,名字不能乱

我们来访问一下,如图:

原文地址:https://www.cnblogs.com/yunquan/p/10346491.html