以下是MyMvcConfig.java配置类的代码,可供参考:
package com.springboot.config; import com.springboot.conponent.LoginHanderInterceptor; import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.HandlerInterceptor; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; /** * @author zhuhonggen * @version 创建时间:2019/08/06 21:05 * @ClassName 类名称 * @Description 类描述 */ @Configuration public class MyMvcConfig implements WebMvcConfigurer { @Bean public WebMvcConfigurer webMvcConfigurer(){ WebMvcConfigurer adpater = new WebMvcConfigurer() { @Override public void addViewControllers(ViewControllerRegistry registry) { registry.addViewController("/").setViewName("login"); registry.addViewController("/login.html").setViewName("login"); //使用重定向 //registry.addViewController("/index.html").setViewName("login"); registry.addViewController("/main.html").setViewName("dashboard"); } @Override public void addInterceptors(InterceptorRegistry registry) { //registry.addInterceptor(new LoginHanderInterceptor()).addPathPatterns("/**").excludePathPatterns("/","/login.html","/action/login","/error/404"); } }; return adpater; } }
以下是该配置类的文件目录结构:
原文地址:https://www.cnblogs.com/jums/p/11323658.html
时间: 2024-11-29 03:30:07