首页>代码>Spring Boot+Maven+Spring Data JPA+Layui实现销售培训考评系统>/topsec_hr/src/main/java/cn/temptation/config/LoginInterceptor.java
package cn.temptation.config;

import cn.temptation.domain.User;
import org.springframework.stereotype.Service;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

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

@Service
public class LoginInterceptor extends HandlerInterceptorAdapter {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();
        User user = (User) session.getAttribute("user");
        // 未登录去登录
        if (null == user) {
            // 注意:这里需要写上"/login",而不是"login",否则重定向的地址只会替换最后一个"/"后面的字符串
            response.sendRedirect("/login");
        }
        return true;
    }
}
最近下载更多
Seaskye  LV14 2023年11月4日
dzlwindy  LV8 2023年6月29日
张真狗  LV9 2023年6月10日
jhh123  LV4 2023年5月28日
zhunishimian  LV6 2023年5月22日
qq2901732871  LV9 2023年5月5日
java小书童  LV17 2023年3月29日
17861270371  LV1 2023年2月22日
jxtzuidaima  LV8 2023年1月31日
rain112  LV30 2022年12月30日
最近浏览更多
玖零定制问题修复  LV34 4月4日
阿凡达  LV9 1月10日
Dominick  LV14 2023年12月27日
admin_z  LV22 2023年12月26日
hhh12345  LV7 2023年12月23日
jiyun2021  LV9 2023年12月2日
murphy  LV6 2023年11月20日
fff2003  LV6 2023年11月17日
Seaskye  LV14 2023年11月4日
3334004690  LV3 2023年11月1日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友