当前位置:网站首页>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");
}
}
边栏推荐
- SQL注入详解
- Comparison of oracle's number and postgresql's numeric
- 在AWS-EC2中安装Minikube集群
- 【Copy攻城狮日志】飞浆学院强化学习7日打卡营-学习笔记
- LeetCode_Nov_5th_Week
- MFC读取点云,只能正常显示第一个,显示后面时报错
- 腾讯、网易纷纷出手,火到出圈的元宇宙到底是个啥?
- MNIST Handwritten Digit Recognition - Image Analysis Method for Binary Classification
- 图像合并水平拼接
- [Copy Siege Lion Log] Flying Pulp Academy Intensive Learning 7-Day Punch Camp-Study Notes
猜你喜欢
No matching function for call to 'RCTBridgeModuleNameForClass'
Cut the hit pro subtitles export of essays
LeetCode_Nov_5th_Week
Deep Learning Theory - Initialization, Parameter Adjustment
tmux概念和使用
DeblurGAN-v2: Deblurring (Orders-of-Magnitude) Faster and Better 图像去模糊
Transformer
彻底删除MySQL教程
Copy Siege Lions "sticky" to AI couplets
The second official example analysis of the MOOSE platform - about creating a Kernel and solving the convection-diffusion equation
随机推荐
Install Minikube Cluster in AWS-EC2
[开发杂项][编辑器][代码阅读]ctags&vim
YOLOV4流程图(方便理解)
【论文阅读】TransReID: Transformer-based Object Re-Identification
MNIST手写数字识别 —— ResNet-经典卷积神经网络
Unity ML-agents 参数设置解明
Code to celebrate the Dragon Boat Festival - Zongzi, your heart
AWS使用EC2降低DeepRacer的训练成本:DeepRacer-for-cloud的实践操作
集合--LinkedList
Tencent and NetEase have taken action one after another. What is the metaverse that is so popular that it is out of the circle?
LeetCode_Dec_3rd_Week
Comparison of oracle's number and postgresql's numeric
第二章 STA相关概念
MNIST手写数字识别 —— Lenet-5首个商用级别卷积神经网络
tensorRT教程——使用tensorRT OP 搭建自己的网络
MOOSE平台使用入门攻略——如何运行官方教程的例子
"A minute" Copy siege lion log 】 【 run MindSpore LeNet model
迅雷关闭自动更新
FAREWARE ADDRESS
MNIST Handwritten Digit Recognition - Building a Perceptron from Zero for Two-Classification