在HandlerInterceptor中获取RequestBody和ResponseBody [英] Get RequestBody and ResponseBody at HandlerInterceptor
问题描述
逻辑我必须实现的是记录所有请求,并将身体提供给DB。
Logic I have to implement is logging all requests with body served to DB.
所以我决定使用: afterCompletion
HandlerInterceptor
的方法。
有两个参数传递给此方法 HttpServletRequest
和 HttpServletResponse
等等。
So I decided to use: afterCompletion
method of HandlerInterceptor
.
There are two parameters passed to this method HttpServletRequest
and HttpServletResponse
among the others.
问题是:如何从提供的对象获取 RequestBody
和 ResponseBody
?
Question is: how to get RequestBody
and ResponseBody
from supplied objects?
据我所知,我们可以使用 @RequestBody
和 @ResponseBody
。我可以在 HandlerInterceptor
中重复使用它们吗?
As far as I know at Controller we can use @RequestBody
and @ResponseBody
. Can I reuse them at HandlerInterceptor
?
推荐答案
据我所知, RequestBody
和 ResponseBody
只能读取一次。所以你不应该在 Interceptor
中阅读它们。
这里有一些解释。
As far as I know, RequestBody
and ResponseBody
can be read only once. So you should not read them in an Interceptor
.
Here's some explanation.
这篇关于在HandlerInterceptor中获取RequestBody和ResponseBody的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!