次の構成は、参考のために、MyMvcConfig.javaクラスコードです。
パッケージcom.springboot.config。 輸入com.springboot.conponent.LoginHanderInterceptor。 輸入org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration。 輸入org.springframework.context.annotation.Bean。 輸入org.springframework.context.annotation.Configuration。 輸入org.springframework.web.servlet.HandlerInterceptor。 輸入org.springframework.web.servlet.config.annotation.InterceptorRegistry。 輸入org.springframework.web.servlet.config.annotation.ViewControllerRegistry。 輸入org.springframework.web.servlet.config.annotation.WebMvcConfigurer。 / ** *@author zhuhonggen * @version 创建时间:2019年8月6日午前21時05 * @ClassName类名称 * @description类描述 * / @Configuration パブリック クラス MyMvcConfigが実装WebMvcConfigurerを{ @Bean 公共WebMvcConfigurer webMvcConfigurer(){ WebMvcConfigurer特殊なアダプタ = 新しいWebMvcConfigurer (){ @Override 公共 ボイドaddViewControllers(ViewControllerRegistryレジストリ){ registry.addViewController( "/").setViewName("login" )。 registry.addViewController("/login.html").setViewName("login" ); // 使用重定向 // registry.addViewController( "/ index.htmlを")setViewName( "ログイン")。 registry.addViewController( "/ main.htmlを")setViewName( "ダッシュボード"。); } @Override 公共 無効addInterceptors(InterceptorRegistryレジストリ){ // registry.addInterceptor(新LoginHanderInterceptor())。addPathPatterns( "/ **")。excludePathPatterns( "/"、 "/ login.htmlと"、 "/アクション/ログイン"、"/エラー404"); } }。 リターン特殊なアダプタ。