当前位置:网站首页>登录拦截器
登录拦截器
2022-06-25 22:03:00 【-LM-】
登录拦截器
Myconfig.java
@Component
public class MyConfig implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/**").excludePathPatterns("/","/user","/login","/echarts/**","/img/**","/layui/**","/login.html","/code");
}
}
LoginInterceptor
public class LoginInterceptor implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
Object user=request.getSession().getAttribute("loginUser");
if(user==null){
request.setAttribute("msg","没有权限,请先登录!");
request.getRequestDispatcher("/login").forward(request,response);
return false;
}else{
return true;
}
}
}
LoginController
// 检查登录用户身份合法性
@RequestMapping("/user")
public String user(@RequestParam("username") String username,
@RequestParam("password") String password,
@RequestParam("captcha") String captcha,Model model, HttpSession session,HttpServletRequest request){
session = request.getSession();
String code = (String) session.getAttribute("code");
System.out.println(code);
System.out.println(captcha);
if(!captcha.equalsIgnoreCase(code.trim())){
model.addAttribute("msg","验证码错误");
return "login";
}
Map<String,Object> mp = new HashMap<>();
mp.put("username",username); mp.put("password",password);
List<User> list = loginService.checkuser(mp);
if(list.size()>0){
session.setAttribute("loginUser",username);
return "index";
}else{
model.addAttribute("msg","账号或密码错误");
return "login";
}
}
边栏推荐
- Konva series tutorial 2: drawing graphics
- Architecture part -- the use of UMI framework and DVA
- 28 rounds of interviews with 10 companies in two and a half years (including byte, pinduoduo, meituan, Didi...)
- Uniapp -- list page of multi header tabs
- mongodb
- php性能优化
- String对象(常量)池
- UE4 学习记录二 给角色添加骨架,皮肤,及运动动画
- 分享一个OSGeo4W64下载好的库,基于qgis3.10的
- Mutual conversion between QT utf8 and Unicode encoding, and the Unicode encoding output format is &xxxxx
猜你喜欢

Beacon realizes asset management and indoor positioning based on 5.2 ultra-low power Bluetooth module efr32 (bg22ax)

中序线索二叉树

提取系统apk

Konva series tutorial 2: drawing graphics

Reprint: detailed explanation of qtablewidget (style, right-click menu, header collapse, multiple selection, etc.)

CSDN添加页内跳转和页外指定段落跳转

Kylin

character string

转载: QTableWidget详解(样式、右键菜单、表头塌陷、多选等)

QT custom implemented calendar control
随机推荐
Windows redis installation and simple use
解决‘tuple‘ object has no attribute ‘lower‘
Kylin
A. Balance the Bits--Codeforces Round #712 (Div. 1)
树状类查询组件
提取系统apk
#24class静态成员
213.打家劫舍 II
The software test interview has been suspended. The interviewer always says that the logical thinking is chaotic. What should I do?
character string
记录一下Qt将少量图片输出为MP4的思路及注意事项
第六章 习题(678)【微机原理】【习题】
Use of xinchida ble 5.0 Low Power Bluetooth module (at command serial port transparent transmission) rsbrs02abr
Reproduction of an implant found by Kaspersky that writes shellcode into evenlog
[opencv450 samples] read the image path list and maintain the proportional display
平衡二叉树AVL
CSDN add on page Jump and off page specified paragraph jump
A. Balance the Bits--Codeforces Round #712 (Div. 1)
Analysis on resource leakage /goroutine leakage / memory leakage /cpu full in go
debezium