当前位置:网站首页>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");
}
}
边栏推荐
- Brief description of database and common operation guide
- FAREWARE ADDRESS
- 结构体内存对齐-C语言
- LeetCode_Nov_4th_Week
- 亚马逊云科技Build On-Amazon Neptune基于知识图谱的推荐模型构建心得
- MySQL批量修改时间字段
- LeetCode_Nov_1st_Week
- C语言对文件的操作(完整版)
- Question 1000: Input two integers a and b, calculate the sum of a+b, this question is multiple sets of test data
- 安装pyspider后运行pyspider all后遇到的问题
猜你喜欢
随机推荐
Amazon Cloud Technology Build On 2022 - AIot Season 2 IoT Special Experiment Experience
LeetCode_Nov_4th_Week
安装Apache服务时出现的几个问题, AH00369,AH00526,AH00072....
MySQL存储过程学习笔记(基于8.0)
FAREWARE ADDRESS
机器学习——分类问题对于文字标签的处理(特征工程)
关于DG(域泛化)领域的PCL方法的代码实例
C语言数组的深度分析
LeetCode_Dec_2nd_Week
动态内存管理-C语言
集合---ArrayList的底层
Design and implementation of legal aid platform based on asp.net (with project link)
arm-3-中断体系结构
EL表达式
[日常办公][杂项][vscode]tab space
【五一专属】阿里云ECS大测评#五一专属|向所有热爱分享的“技术劳动者”致敬#
2020-03-27
file editor
file permission management ugo
Pytest common plug-in