Springboot 实现WebMvcConfigurer接口来拓展SpringMvc的功能
好像是Spring Boot 2.0.4.RELEASE
中WebMvcConfigurerAdapter
已过时,所以想通过继承WebMvcConfigurerAdapter来拓展SpringMvc的功能时会有一条删除线。
因此,通过实现WebMvcConfigurer接口来拓展SpringMvc的功能()
package com.example.springboot.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@Configuration
public class MyMvcConfig implements WebMvcConfigurer {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
////浏览器发送 /nihao 请求来到 success
registry.addViewController("/nihao").setViewName("success");
}
}