Springboot 實現默認訪問歡迎頁登錄頁

我們想要讓項目啓動  訪問端口後 直接默認進入登錄頁  用下面方式實現

 

首先  我們創建一個MVC的類  繼承WebMvcConfigurerAdapter 這個類。

 

DefaultController.java

package com.example.controller.defaultMVC;

import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.boot.autoconfigure.web.ResourceProperties;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcProperties;
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 DefaultController extends WebMvcConfigurerAdapter {

	@Override
	   public void addViewControllers( ViewControllerRegistry registry ) {
	       registry.addViewController( "/" ).setViewName( "forward:/index.jsp" );
	       registry.setOrder( Ordered.HIGHEST_PRECEDENCE );
	       super.addViewControllers( registry );
	   }

}

這個時候訪問localhost:端口號/   就會默認跳轉到index.jsp

指定頁面

然後在給你加上這個視圖解析器的  yml配置吧

  mvc:
    view:
     prefix : /
     suffix : .jsp

prefix:    後面這裏是你的jsp路徑  可以百度一下這個標籤  ok   結束  有用點個贊

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章