【发布时间】:2016-06-15 13:19:19
【问题描述】:
我想构建一个库,将请求和响应的 Json 内容保存在带注释的 Spring 控制器上。
所以我建立了自己的注解 @Foo 并将它放在一些控制器上:
@Foo
@RequestMapping(method = RequestMethod.POST, value = "/doSomeThing", produces = {
MediaType.APPLICATION_JSON_VALUE, MediaType.TEXT_XML_VALUE,
MediaType.APPLICATION_XML_VALUE})
public ResponseEntity<T> doSomething(/*some parameters*/) {
T t = doSomeJob(T.class);
return new ResponseEntity<T>(t, HttpStatus.OK);
}
我不保证请求和响应在 Contreller 的参数中! 而且我在 @AfterReturning AOP 切入点内对任何具有该注释的控制器进行了调用。
@Component
@Aspect
public class XYInterceptor
@AfterReturning(
pointcut = "execution(@my.annotation.Foo)")
public void doSomethingWithJsonContent(JoinPoint joinPoint) throws Throwable {
//How can i get json value of request and response here?
}
如何获取 json 格式的请求和响应内容(例如发送/返回给客户端)?
感谢您的帮助!
【问题讨论】:
-
请在这个帖子stackoverflow.com/a/50712697/3073945查看我的答案
标签: json spring annotations request aop