[英]ajax returning null for large amount of data from spring controller
I try to return data from controller to AJAX success() callback. 我尝试将数据从控制器返回到AJAX success()回调。 This code perfectly works for 100,000 objects.
该代码完美适用于100,000个对象。 But when I increase size of list to 1 million objects, it goes to success() callback, but returning null as response.
但是,当我将list的大小增加到100万个对象时,它将转到success()回调,但是返回null作为响应。 Could you help me with finding the way to return 1 mln of objects?
您能帮我找到返回100万个对象的方法吗?
A.$.ajax({ url: 'getData', dataType: 'json', success: function (response) { alert(response) }
@RequestMapping("/getData") public @ResponseBody void download(HttpServletResponse response ) throws IOException, JSONException { List <Objects> list = getListFromService(); response.setContentType("application/json"); PrintWriter out = response.getWriter(); ObjectMapper mapper = new ObjectMapper(); String jsonString = mapper.writeValueAsString(list); out.print(jsonString); out.flush(); }
Your method is annotated with @ResponseBody but it's return type is void. 您的方法带有@ResponseBody注释,但其返回类型为void。 Try to return your List directly, and let Spring handle the JSON processing for you:
尝试直接返回您的List,然后让Spring为您处理JSON处理:
@RequestMapping("/getData")
public @ResponseBody List<Objects> download( ) {
return getListFromService();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.