我正在尝试找出将以下内容重新分解为 http asynch GET 场景的最佳方法,其中并行处理多个 http GET,然后 1)等待 http 响应返回并将相应的响应数据传递到视图中或 2) 立即返回视图,并在收到来自每个 http GET 的响应后以某种方式从我的控制器或回调异步更新视图中的 div。
这是我目前在同步处理的当前状态下所拥有的。
Spring MVC 控制器(当前):MyController.java
// Make multiple http calls...get the values from each call and pass into the view
@RequestMapping(value="", method = RequestMethod.GET)
public String index(ModelMap model) {
// http.getData calls apache HttpGet httpget = new HttpGet(url); ... to get values
String values2 = http.getData(http://mysrv.com/data?stuff="1").toString();
model.addAttribute("highchartvalues1", highchartvalues1);
String values2 = http.getData(http://mysrv.com/data?stuff="2").toString();
model.addAttribute("highchartvalues2", highchartvalues2);
return "index";
}
查看(.jsp/jstl):index.jsp
// the values are actually consumed via highcharts
<div id="highchart1">${highchartvalues1}</div>
<div id="highchart2">${highchartvalues2}</div>