SpringBoot页面跳转配置(接管springMVC)(非一个页面一个空方法)

当我们访问页面时,如果没有其他数据上的请求而只是一个纯粹的页面的跳转问题,那么我们可以自己创建一个配置类直接进行配置,就免去了一个页面一个空方法的步骤,代码如下:

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

@Configuration
public class MyMvcConfig extends WebMvcConfigurerAdapter {
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/index").setViewName("index");
        registry.addViewController("/indexTest").setViewName("index");
    }
}

其中registry.addViewController("/indexTest").setViewName("index");
中的addViewController的参数为我们请求的路径,而setViewName是我们请求所要返回的路径。

猜你喜欢

转载自blog.csdn.net/qiuqiu1628480502/article/details/81360600