在HandlerInterceptor中获取RequestBody和ResponseBody [英] Get RequestBody and ResponseBody at HandlerInterceptor

查看:546
本文介绍了在HandlerInterceptor中获取RequestBody和ResponseBody的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

逻辑我必须实现的是记录所有请求,并将身体提供给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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆