当前位置:网站首页>MVC custom configuration
MVC custom configuration
2022-08-04 06:36:00 【Louzen】
学习资料
MVC自定义配置
实现WebMvcConfigurer接口,并重写相关方法
自定义拦截器(Login interception as an example)
// 1、先定义一个拦截器,实现HandlerInterceptorInterface and implement the three methods inside
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进行自定义配置,重写addInterceptorsmethod to add a custom interceptor
@Configuration
public class AdminWebConfig implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new LoginInterceptor())
.addPathPatterns("/**")
.excludePathPatterns("/", "/login");
}
}
边栏推荐
猜你喜欢
The second official example analysis of the MOOSE platform - about creating a Kernel and solving the convection-diffusion equation
Copy Siege Lion 5-minute online experience MindIR format model generation
MNIST Handwritten Digit Recognition - Building a Perceptron from Zero for Two-Classification
线性表之动态数组(ArrayList)的自实现
Socket编程详解
AWS使用EC2降低DeepRacer的训练成本:DeepRacer-for-cloud的实践操作
通用解决端口占用问题
库函数的模拟实现-C语言
arm学习-1-开发板
LeetCode_Nov_5th_Week
随机推荐
第一章 绪论
EL表达式
结构体传参-C语言
安装pyspider后运行pyspider all后遇到的问题
[日常办公][ssh]cheatsheet
亚马逊云科技Build On-Amazon Neptune基于知识图谱的推荐模型构建心得
[Copy Siege Lion Log] Flying Pulp Academy Intensive Learning 7-Day Punch Camp-Study Notes
MNIST Handwritten Digit Recognition - Building a Perceptron from Zero for Two-Classification
Deep Learning Theory - Overfitting, Underfitting, Regularization, Optimizers
C语言数组的深度分析
[Daily office][shell] Common code snippets
深度学习理论——过拟合、欠拟合、正则化、优化器
Thunderbolt turns off automatic updates
makefile基础学习
Stream API
A code example of the PCL method in the domain of DG (Domain Generalization)
MOOSE平台使用入门攻略——如何运行官方教程的例子
JDBC第一学之进行数据库连接时出现The server time zone.....解决办法
LeetCode_22_Apr_2nd_Week
Object. RequireNonNull method