1.直接寫一個配置類繼承WebMvcConfigurerAdapter即可
具體代碼如下:
package com.boot.zhiyi.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@Configuration
public class ViewConfig extends WebMvcConfigurerAdapter {
/**
* 控制跳轉頁面
* @param registry
*/
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("forward:html/login.html");
registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
super.addViewControllers(registry);
}
}
這樣的話當我們訪問:localhost:8080/的時候就會跳轉到login頁面