利用@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的更多相关文章

  1. spring aop 加在Controller层造成类初始化两遍

    写一个测试项目,在配置动态数据源的时候采用的AOP切面到Controller层中,根据参数判断是否切合数据源,结果发现,每次Controller层的类都会初始化两次! 后来测试发现,把切面放到Serv ...

  2. Spring Mvc 在非controller层 实现获取request对象

    一般我们在Controller层,会编写类似这样的方法 @Controller @RequestMapping(value="/detail") public class GetU ...

  3. ssh_maven之controller层开发

    我们已经完成了前两层的开发,现在 只剩下我们的controller层了,对于这一层,我们需要创建一个动作类CustomerAction,另外就是我们的strutss.xml以及我们的applicati ...

  4. 【异常处理】Springboot对Controller层方法进行统一异常处理

    Controller层方法,进行统一异常处理 提供两种不同的方案,如下: 方案1:使用 @@ControllerAdvice (或@RestControllerAdvice), @ExceptionH ...

  5. Controller层的方法访问标志与Spring装配与AspectJ切面处理

    最近在做AspectJ实现的日志模块,在spring配置中加入了<aop:aspectj-autoproxy/>,之后发现,只要有用到自定义注解的类,某些方法经MVC请求时就报空指针错误. ...

  6. springMVC中controller层方法中使用private和public问题

    楼主一直习惯使用public,偶尔手误也可能使用private,但是发觉也没啥区别,都能调用service层,注入bean. 后来做一个新项目时,发觉自己以前的写的部分功能报错,当时有点懵逼,,找了半 ...

  7. Springboot对Controller层方法进行统一异常处理

    Controller层方法,进行统一异常处理 提供两种不同的方案,如下: 方案1:使用 @@ControllerAdvice (或@RestControllerAdvice), @ExceptionH ...

  8. DAO层,Service层,Controller层、View层 的分工合作

    DAO层:DAO层主要是做数据持久层的工作,负责与数据库进行联络的一些任务都封装在此,DAO层的设计首先是设计DAO的接口,然后在Spring的配置文件中定义此接口的实现类,然后就可在模块中调用此接口 ...

  9. Junit mockito 测试Controller层方法有Pageable异常

    1.问题 在使用MockMVC+Mockito模拟Service层返回的时候,当我们在Controller层中参数方法调用有Pageable对象的时候,我们会发现,我们没办法生成一个Pageable的 ...

随机推荐

  1. sql语言 含有包含关系的查询 (含mysql 和sql sever)

    一.sql中查询包含关系的查询 sql语句中包含关系可以使用 in 和exist,但有些时候仅仅用这两个是不够的,还有表示方法是  not exist(b expect a )可以表示a包含b. 二. ...

  2. https原理及其中所包含的对称加密、非对称加密、数字证书、数字签名

    声明:本文章已授权公众号Hollis转载,如需转载请标明转载自https://www.cnblogs.com/wutianqi/p/10654245.html(安静的boy) 一.为什么要使用http ...

  3. R随机森林交叉验证 + 进度条

    library(data.table) library(randomForest) data <- iris str(data) #交叉验证,使用rf预测sepal.length k = 5 d ...

  4. ILBC 规范

    本文是 VMBC / D# 项目 的 系列文章, 有关 VMBC / D# , 见 <我发起并创立了一个 VMBC 的 子项目 D#>(以下简称 <D#>) https://w ...

  5. angularjs 的模型无法绑定到隐藏域(input hidden)

    描述一下问题: 在操作表单中的隐藏域的时候发现angularjs的模型无法绑定,比如: <input type="hidden" name="someData&qu ...

  6. Java_集合面试题

    Java_集合面试题 0.链表,队列和栈的区别? 链表是一种存储结构,指得是存储时候除了要存储数据元素之外,还要用数据元素一起的另外空间存储数据元素的关系. 队列和栈都是线性表,属于逻辑结构范畴,都是 ...

  7. Windows下将文件打包压缩成 .tar.gz格式

    1.下载 “7-ZIP”,安装完成后进入需要打包的文件夹 2. 右击选择“添加到压缩包” 3.压缩格式:tar 4. 得到.tar文件,将其打包 5. 压缩格式为:gzip 6. 得到tar.gz格式 ...

  8. Python 模块collections

    1.深入理解python中的tuple的功能 基本特性 # 可迭代 name_tuple = ('0bug', '1bug', '2bug') for name in name_tuple: prin ...

  9. Qt配置cmake;运行带参数的程序

    配置cmake编译器,步骤如下: 步骤1:  Qt下新建一个project. 步骤2:  在该project目录下创建一个CMakeLists.txt文件,并按规范编写该文件. Tip: projec ...

  10. cookie.js插件

    /*! cookiejs v1.0.23 | MIT (c) 2018 kenny wong | https://github.com/jaywcjlove/cookie.js */!function ...