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的 ...
随机推荐
- WEB学习笔记1-综述
WEB前端基本技术:HTML.CSS.JavaScript 概念: 从职责上讲,Web前端开发要涉及网站开发的方方面面,从前端UI到和后端的数据交互都属于前端开发的范畴.Web前端开发是兼具艺术气息和 ...
- 双跑道------js分机号
博客园 首页 新随笔 联系 管理 订阅 随笔- 310 文章- 0 评论- 134 [tomcat]启动报错:Failed to initialize end point associated ...
- yuan的第二次随笔
第一题: 计算两数的和与差 设计思路: 1:看题目:主函数与函数声明,知道它要你干什么 2:理解与分析:在main中,定义两个实数a,b;要你求两数的和与差 3:解答:通过调用函数sum_diff,指 ...
- Python全栈之路----数据类型—列表
1.列表是一个数据的集合,集合内可以放任何数据类型,可对集合进行方便的增删改查操作.列表里面的数可以重复. L1 = [ ] #定义空列表 L2 = [ 'a' , 'b' , 'c' , 'd' ] ...
- 数组,集合,字符串,bean,map
//[字符串]转成[数组] String[] arr = "1,2,3,4,5,6".split(","); //[String数组]转成[Long数组] Lo ...
- Javascript 2.8
声明函数声明参数 function multiply(A,B,...N){}; 用return可以返回一个值/字符串/数组/布尔值 变量命名的Camel记号:从第二个单词开始把每个单词的首字母大写,其 ...
- hdu5007 Post Robot AC自动机
DT is a big fan of digital products. He writes posts about technological products almost everyday in ...
- Go Example--panic
package main import "os" func main() { //panic会中断程序执行,在此处一直往上抛panic,需要上游的recover来捕获 panic( ...
- 列表:remove/del删除方法中的逻辑“误区”
结果: list_1=["A","B","C","D","E","F",&quo ...
- hsdfz -- 6.18 -- day3
第三次被hn菜和hn话支配…… 相比起前两天好一点,但是由于前面时间安排的太散(睡着了……)导致c题DP差一点肝出来(所以最后没有…… 恩就算肝出来DP也只有30分,这次好歹是有DP思路了,继续康复吧 ...