通过更改正文和标题从一个控制器重定向到另一个控制器

时间:2017-06-27 09:02:15

标签: java spring rest redirect request

我有通用控制器,它有编码的请求体。我想这个控制器解码体并设置这个解码的主体并重定向到特定的控制器。以下是我的控制器

@RequestMapping(value = "/{type}", method = RequestMethod.POST)
public String save(@RequestBody String base64Body, @PathVariable("type") String type) throws IOException {

    String json = decompress(Base64.getDecoder().decode(base64Body));

    //now I'd like set json to request body, change header, and redirect to "type" controller
    return format("redirect:/%s/save", type);
}

上面的代码应该从addres / type / save调用我的控制器和解码后的身体,它甚至可能吗?感谢

1 个答案:

答案 0 :(得分:0)

format("redirect:/%s/save/json=%s", type, json);

或者只是将重定向目标控制器自动装配到主控制器并直接调用该方法而不使用http传输。