修改响应对象由端点驱动

发布于 2025-01-29 09:29:45 字数 586 浏览 3 评论 0原文

我有一个端点方法返回项目列表,我想知道如何拦截此列表以应用一些修改:

@PostMapping(value="/someUrl")
public List<Items> find(@RequestBody Command cmd){
   //do something
   return arrayListOfItems;
}

我尝试使用handlerinterceptor httpservletresponse 在这里?,如果不是最好的解决方案?

public void postHandle(HttpServletRequest request, HttpServletResponse response, Object o, ModelAndView modelAndView) throws IOException {
                    
           //how can I get the returned List<Items> and modify it here, before returning it to the client 
}

I have an endpoint method that returns a List of Items, I wonder how can I intercept this list to apply some modifications for example:

@PostMapping(value="/someUrl")
public List<Items> find(@RequestBody Command cmd){
   //do something
   return arrayListOfItems;
}

I tried to do using HandlerInterceptor, is it possible to get the returned list from the HttpServletResponse here?, if not what is the best solution ?

public void postHandle(HttpServletRequest request, HttpServletResponse response, Object o, ModelAndView modelAndView) throws IOException {
                    
           //how can I get the returned List<Items> and modify it here, before returning it to the client 
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文