春ブーツのデフォルトページ

春ブーツデフォルトのウェルカム画面はメイン/リソース/静的/ index.htmlにあります。

春ブーツは、デフォルトのページを変更します

元WebMvcConfigurerAdapterは、古くなっ継承WebMvcConfigurationSupportクラスに置き換えたりWebMvcConfigurerインタフェースを実装しています。

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.WebMvcConfigurationSupport;

@Configuration
public class DefaultViewConfig extends WebMvcConfigurationSupport {

    @Override
    public void addViewControllers(ViewControllerRegistry registry){
        //设置访问路径为 “/”
        registry.addViewController("/").setViewName("login.html");
        //设置为最高优先级
        registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
        super.addViewControllers(registry);
    }
}

設定クラス、継承WebMvcConfigurationSupportクラスを書き込むことにより、addViewController()メソッドをオーバーライドします。

registry.addViewController("/").setViewName("login.html");

このコードは、に対応します

@Controller
public class TestController{
    @RequestMapping("/")
    public String testController(){
        return "login";
    }
}

アクセスするには、ブラウザにhttp:// localhost:8080 /メイン/リソース/静的/ login.htmlとにアクセスすることができます。