【问题标题】:How to retrieve value of parameters annotated by @RequestBody from a HttpServeletRequest object?如何从 HttpServeletRequest 对象中检索 @RequestBody 注释的参数值?
【发布时间】:2019-06-16 15:24:37
【问题描述】:

在 springcloud 项目中 如果后端微服务具有以下内容:

@RequestMapping("/test")
pubilc void test(@RequestBody MyPram myParam){
    ...
}

如何在 zuul 过滤器中检索“myParam”值? 换句话说,因为我可以在zuul过滤器中有以下代码段

    RequestContext ctx = RequestContext.getCurrentContext();
    HttpServletRequest request = ctx.getRequest();

如何从请求中检索“myParam”值?

【问题讨论】:

  • 你不能,因为 Zuul 对此一无所知。

标签: java spring spring-mvc netflix-zuul


【解决方案1】:

我不知道在 Spring Cloud 中,但在 springMVC(spring 版本 3)中尝试过,我们可以获取请求主体 HttpServeletRequest 对象或方法。

@RequestMapping(value="/employee/{id}") public @ResponseBody String demo(HttpServletRequest request, @PathVariable("id") Integer id) {

    if (request.getMethod().equalsIgnoreCase("POST")) {
        return "POST MEhod";
    } else if (request.getMethod().equalsIgnoreCase("GET")) {
        return "GET Method";
     }
      }

它不完全是你在寻找什么,但它会给你提示来解决你的问题

【讨论】:

    猜你喜欢
    • 2019-01-07
    • 1970-01-01
    • 2019-05-28
    • 1970-01-01
    • 2020-04-07
    • 2013-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多