博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
spring boot 1.x 拦截器
阅读量:7063 次
发布时间:2019-06-28

本文共 1319 字,大约阅读时间需要 4 分钟。

hot3.png

1、拦截器统一管理

@Configurationpublic class AppConfig extends WebMvcConfigurerAdapter {	@Resource	private FRInterceptor fRInterceptor;	@Override	public void addInterceptors(InterceptorRegistry registry) {		//自定义拦截器,添加拦截路径和排除拦截路径 		registry.addInterceptor(fRInterceptor).addPathPatterns("api/**").excludePathPatterns("api/login"); ;	}}

2、自定义拦截器

@Componentpublic class FRInterceptor implements HandlerInterceptor {	/*	 * 视图渲染之后的操作	 */	@Override	public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3)			throws Exception {	}	/*	 * 处理请求完成后视图渲染之前的处理操作	 */	@Override	public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView arg3)			throws Exception {	}	/*	 * 进入controller层之前拦截请求	 */	@Override	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object obj) throws Exception {		System.out.println("getContextPath:" + request.getContextPath());		System.out.println("getServletPath:" + request.getServletPath());		System.out.println("getRequestURI:" + request.getRequestURI());		System.out.println("getRequestURL:" + request.getRequestURL());		System.out.println("getRealPath:" + request.getSession().getServletContext().getRealPath("image"));		return true;	}}

 

转载于:https://my.oschina.net/u/182501/blog/1602342

你可能感兴趣的文章
08R2-12R2基于访问权限的文件枚举
查看>>
Gartner:网络信息安全投入依然不在中国政企客户优先投入之列
查看>>
恢复误删除的ESXi服务器存储VMFS卷
查看>>
SFB 项目经验-22-如何查看存储的管理IP地址
查看>>
libevent入门教程:Echo Server based on libevent
查看>>
.NET/ASP.NETMVC 大型站点架构设计—迁移Model元数据设置项(自定义元数据提供程序)...
查看>>
一次服务器CPU占用率高的定位分析
查看>>
安装office2007 1706错误
查看>>
crontab中执行多条命令
查看>>
25 JavaScript的幻灯片用于在Web布局的精彩案例
查看>>
用C语言写的迅雷看看XV文件提取器及C语言源代码
查看>>
ccpuid:CPUID信息模块 V1.01版,支持GCC(兼容32位或64位的Windows/Linux)
查看>>
用dom4j操作XML文档(收集)
查看>>
WinForm实例源代码下载
查看>>
hdu 1829 A Bug's Life(并查集)
查看>>
每日英语:Chinese Writer Wins Literature Nobel
查看>>
java中三种主流数据库数据库(sqlserver,db2,oracle)的jdbc连接总结
查看>>
Oracle Apps AutoConfig
查看>>
[leetcode]Flatten Binary Tree to Linked List
查看>>
css颜色代码大全:(网页设计师和平面设计师常用)
查看>>