首页>代码>spring boot+spring mvc+mybatis+thymeleaf整合开发学生成绩信息管理系统>/src/main/java/com/zhengyuan/liunao/config/WebSecurityConfig.java
package com.zhengyuan.liunao.config;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

@Configuration
public class WebSecurityConfig extends WebMvcConfigurerAdapter{
	public static final String SESSION_KEY="name";
	 @Bean
	    public SecurityInterceptor getSecurityInterceptor(){
	        return  new SecurityInterceptor();
	    }
	    @Override
	    public  void addInterceptors(InterceptorRegistry registry){
	        InterceptorRegistration addInterceptor = registry.addInterceptor(getSecurityInterceptor());
	 
	        //排除配置
	        addInterceptor.excludePathPatterns("/Sys/loginView","/Sys/dealLogin","/Sys/css/**","/Sys/fonts/**","/Sys/images/**","/Sys/js/**","/Sys/lau/**","/Sys/lib/**");
	        //拦截配置
	        addInterceptor.addPathPatterns("/**/**");
	    }
	 
	    private class SecurityInterceptor extends HandlerInterceptorAdapter {
	        @Override
	        public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)throws IOException{
	            HttpSession session = request.getSession(true);
	            //判断是否已有该用户登录的session
	            if(session.getAttribute("name") !=null){
	                return  true;
	            }
	            //跳转到登录页
	            String url = "/Sys/loginView";
	            response.sendRedirect(url);
	            return false;
	        }
	    }


}
最近下载更多
牛牛要爆炸了  LV2 1月2日
赵鑫cdsaljkdfsa  LV11 2024年7月2日
17693282606  LV12 2024年6月5日
ma406805131  LV19 2024年6月2日
来一杯西瓜冰咩  LV6 2024年5月16日
都天星泪  LV2 2024年3月24日
微信网友_6795583448387584  LV2 2023年12月28日
admin_z  LV22 2023年12月22日
pangzhihui  LV14 2023年12月20日
五折也挺好的  LV13 2023年9月22日
最近浏览更多
牛牛要爆炸了  LV2 1月2日
zy123456xdasd 2024年12月29日
暂无贡献等级
xinshou11111x 2024年12月12日
暂无贡献等级
2378703771 2024年12月9日
暂无贡献等级
sjwc88  LV3 2024年12月4日
Long1022gnoL 2024年12月4日
暂无贡献等级
TFCXTFCX 2024年12月3日
暂无贡献等级
408889065 2024年11月11日
暂无贡献等级
暂无贡献等级
赵鑫cdsaljkdfsa  LV11 2024年7月2日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友