Controller层aop
利用@Around通知修改Controller的返回值
自定义一个注解@OperationBtn
在切入点Controller上加上自定义注解
接下来就是重点了,AspectJ写切面类,对该Controller 1 @Component
@Aspect
public class OperationBtnAspect { @Autowired
private AppTableOperationServiceI appTableOperationService; @Around(value = "@annotation(anno)", argNames = "anno")
public AjaxJson aroundMthod(ProceedingJoinPoint point, OperationBtn anno) throws Throwable{
RequestAttributes ra = RequestContextHolder.getRequestAttributes();
ServletRequestAttributes sra = (ServletRequestAttributes) ra;
HttpServletRequest request = sra.getRequest(); String url = request.getRequestURL().toString(); // http://localhost:8080/5U/appDataController.do (URL:返回的是完整的url,包括Http协议,端口号,servlet名字和映射路径,但它不包含请求参数。)
String method = request.getMethod(); // POST
String uri = request.getRequestURI(); // /5U/appDataController.do
String queryString = request.getQueryString(); // addOrUpdateData&operId=402881e8645f580501645f61202c0044&optId=402881e8645f580501645f61203d004c(返回url路径后面的查询字符串)
queryString = queryString.substring(queryString.indexOf("operId"));
queryString = queryString.substring(,queryString.indexOf("&"));
AppTableOperationEntity operationEntity = appTableOperationService.getEntity(AppTableOperationEntity.class, queryString);
AjaxJson json = (AjaxJson) point.proceed(); //执行Controller中方法,得到返回值json
if(json.isSuccess() && operationEntity !=null && operationEntity.getCallbackSucMsg() !=null){
json.setMsg(operationEntity.getCallbackSucMsg());
}else if(!json.isSuccess() && operationEntity !=null && operationEntity.getCallbackSucMsg() !=null){
json.setMsg(operationEntity.getCallbackFailMsg());
}
return json;
}
}
Controller层aop的更多相关文章
- spring aop 加在Controller层造成类初始化两遍
写一个测试项目,在配置动态数据源的时候采用的AOP切面到Controller层中,根据参数判断是否切合数据源,结果发现,每次Controller层的类都会初始化两次! 后来测试发现,把切面放到Serv ...
- Spring Mvc 在非controller层 实现获取request对象
一般我们在Controller层,会编写类似这样的方法 @Controller @RequestMapping(value="/detail") public class GetU ...
- ssh_maven之controller层开发
我们已经完成了前两层的开发,现在 只剩下我们的controller层了,对于这一层,我们需要创建一个动作类CustomerAction,另外就是我们的strutss.xml以及我们的applicati ...
- 【异常处理】Springboot对Controller层方法进行统一异常处理
Controller层方法,进行统一异常处理 提供两种不同的方案,如下: 方案1:使用 @@ControllerAdvice (或@RestControllerAdvice), @ExceptionH ...
- Controller层的方法访问标志与Spring装配与AspectJ切面处理
最近在做AspectJ实现的日志模块,在spring配置中加入了<aop:aspectj-autoproxy/>,之后发现,只要有用到自定义注解的类,某些方法经MVC请求时就报空指针错误. ...
- springMVC中controller层方法中使用private和public问题
楼主一直习惯使用public,偶尔手误也可能使用private,但是发觉也没啥区别,都能调用service层,注入bean. 后来做一个新项目时,发觉自己以前的写的部分功能报错,当时有点懵逼,,找了半 ...
- Springboot对Controller层方法进行统一异常处理
Controller层方法,进行统一异常处理 提供两种不同的方案,如下: 方案1:使用 @@ControllerAdvice (或@RestControllerAdvice), @ExceptionH ...
- DAO层,Service层,Controller层、View层 的分工合作
DAO层:DAO层主要是做数据持久层的工作,负责与数据库进行联络的一些任务都封装在此,DAO层的设计首先是设计DAO的接口,然后在Spring的配置文件中定义此接口的实现类,然后就可在模块中调用此接口 ...
- Junit mockito 测试Controller层方法有Pageable异常
1.问题 在使用MockMVC+Mockito模拟Service层返回的时候,当我们在Controller层中参数方法调用有Pageable对象的时候,我们会发现,我们没办法生成一个Pageable的 ...
随机推荐
- servlet编程操作
所谓servlet指:服务器处理来自Web浏览器或其他客户端的HTTP请求的服务器程序.客户端向服务器发送Http请求,经Tomcat封装处理转给Servlet容器,Servlet容器在把请求或回应交 ...
- 实现两个矩阵相乘的C语言程序
程序功能:实现两个矩阵相乘的C语言程序,并将其输出 代码如下: #include "stdafx.h" #include "windows.h" void Mu ...
- 国内优秀MVC开源框架jfinal简介
JFinal简介 JFinal 项目开发始于2011年初,作者詹波(James Zhan)曾任搜格信息技术有限公司Java架构师,北京信息管理科学研究所CTO,现任微格网际(北京)科技有限公司联合创始 ...
- #考研笔记#计算机之word问题
Word 问题:1. 如何为文档加密保存?单击 office 按钮\另存为\工具按钮\常规选项\设置打开文件时的密码 2. 怎样在横格稿纸中录入古诗?单击 office 按钮\新建\模板\信纸\稿纸( ...
- springboot 缓存架构
线程内部缓存:a. 局部变量HashMap, 方法间传递 b. 使用ThreadLocal 本地缓存:单jvm内共享 可以使用(Concurrent)HashMap自己实现,也可以使用GuavaCa ...
- Django项目在linux系统中虚拟环境部署
1.在linux系统下,安装virtualenv 命令:pip install virtualenv 2.项目部署前的准备 1. Django web project deployment 1.1. ...
- PythonStudy——数据类型总结 Data type summary
按存储空间的占用分(从低到高) 数字 字符串 集合:无序,即无序存索引相关信息,可变.集合中的元素必须是可hash的,即不可变的数据类型. 元组:有序,需要存索引相关信息,不可变 列表:有序,需要存索 ...
- awk命令过滤tomcat的访日日志中IP地址
1. 命令如下 批量过滤日志文件,grep -v是要排除10网段开头的IP地址 sort会自动按ip排序 uniq -c去重并计数 sort -n 按数值从小到大排序 [root@linux-node ...
- keepalive实现MGR的自动切换(二)
10.0.0.7 lemon 10.0.0.8 lemon2 10.0.0.9 lemon3 程序代码里只需写一个VIP连接数据库即可,后面是连接在哪一台通过,keepalived的在服务端实现: ...
- insert 插入
自动关联当前时间: GETDATE():返回当前时间和日期.