当前位置:网站首页>MVC自定义配置
MVC自定义配置
2022-08-04 05:31:00 【Louzen】
学习资料
MVC自定义配置
实现WebMvcConfigurer接口,并重写相关方法
自定义拦截器(登录拦截为例)
// 1、先定义一个拦截器,实现HandlerInterceptor接口并实现里面的三个方法
public class LoginInterceptor implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
return Objects.nonNull(request.getAttribute("loginUser"));
}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
HandlerInterceptor.super.postHandle(request, response, handler, modelAndView);
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
HandlerInterceptor.super.afterCompletion(request, response, handler, ex);
}
}
// 2、实现WebMvcConfigurer接口对web进行自定义配置,重写addInterceptors方法添加自定义拦截器
@Configuration
public class AdminWebConfig implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new LoginInterceptor())
.addPathPatterns("/**")
.excludePathPatterns("/", "/login");
}
}
边栏推荐
猜你喜欢
深度学习,“粮草”先行--浅谈数据集获取之道
【论文阅读】Exploring Spatial Significance via Hybrid Pyramidal Graph Network for Vehicle Re-identificatio
Golang环境变量设置(二)--GOMODULE&GOPROXY
Halcon缺陷检测
CSDN spree -- college round table spree
"A minute" Copy siege lion log 】 【 run MindSpore LeNet model
剪映专业版字幕导出随笔
Copy Siege Lion 5-minute online experience MindIR format model generation
【Copy攻城狮日志】飞浆学院强化学习7日打卡营-学习笔记
tmux概念和使用
随机推荐
迅雷关闭自动更新
如何成长为高级工程师?
Amazon Cloud Technology Build On 2022 - AIot Season 2 IoT Special Experiment Experience
度量学习(Metric learning、损失函数、triplet、三元组损失、fastreid)
Image-Adaptive YOLO for Object Detection in Adverse Weather Conditions
【五一专属】阿里云ECS大测评#五一专属|向所有热爱分享的“技术劳动者”致敬#
深度学习理论 —— 初始化、参数调节
Pytorch问题总结
MNIST手写数字识别 —— 从二分类到十分类
Code to celebrate the Dragon Boat Festival - Zongzi, your heart
[日常办公][shell]常用代码段
Deep Learning Theory - Overfitting, Underfitting, Regularization, Optimizers
(Navigation page) OpenStack-M version - manual construction of two nodes - with video from station B
MNIST手写数字识别 —— 从感知机到卷积神经网络
FAREWARE ADDRESS
语音驱动嘴型与面部动画生成的现状和趋势
安装pyspider后运行pyspider all后遇到的问题
Deep learning, "grain and grass" first--On the way to obtain data sets
Deep Learning Theory - Initialization, Parameter Adjustment
tmux概念和使用