spring boot項目一般通過Application啟動,且不需要配置web.xml,所以設置默認訪問頁面可以通過以下方法實現,比如增加默認DefaultView類,代碼如下:
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
/**
*
* 項目默認訪問路徑
*/
@Configuration
public class DefaultView extends WebMvcConfigurerAdapter {
@Override
public void addViewControllers(ViewControllerRegistry reg) {
reg.addViewController("/").setViewName("login");//默認訪問頁面
reg.setOrder(Ordered.HIGHEST_PRECEDENCE);//最先執行過濾
super.addViewControllers(reg);
}
}