您将无法通过视图转发来做到这一点。您必须使用 HTTP 客户端从目标 url 获取响应并将该内容写入当前请求的响应正文。
@RequestMapping(value = {"hello/{id}"}, method = RequestMethod.GET)
public void helloGet(Model model, @PathVariable Integer id, HttpServletResponse response) {
final String url = "http://www.google.com"
// use url to get response with an HTTP client
String responseBody = ... // get url response body
response.getWriter().write(responseBody);
}
或与@ResponseBody
@RequestMapping(value = {"hello/{id}"}, method = RequestMethod.GET)
public @ResponseBody String helloGet(Model model, @PathVariable Integer id) {
final String url = "http://www.google.com"
// use url to get response with an HTTP client
String responseBody = ... // get url response body
return responseBody;
}