我的项目基于Java 8,并且整个使用Spring
我有一个返回一个bean的服务,其中包含一个bean列表。
这是代码
API方法
@RequestMapping(value = "/search",", produces = { MediaType.APPLICATION_JSON_VALUE }, method = RequestMethod.POST)
@ResponseBody
public DeferredResult<EmpAdvancedSearchPageBean> getSearch(
@RequestBody final EmpBean empBean) {
LOGGER.info("Pre getSearch");
EmpSearchPageBean searchPageBean = dataService.getSearch(empBean);
LOGGER.info("Post getSearch");
LOGGER.info("Pre set deffered result");
DeferredResult<EmpSearchPageBean> deferredResult = new DeferredResult<>();
deferredResult.setResult(searchPageBean);
LOGGER.info("Post set deffered result");
return deferredResult;
}
EmpSearchPageBean
public class EmpSearchPageBean implements java.io.Serializable {
private static final long serialVersionUID = 8085664391632415982L;
@JsonProperty("draw")
private Integer draw;
@JsonProperty("recordsTotal")
private Integer recordsTotal;
@JsonProperty("recordsFiltered")
private Integer recordsFiltered;
@JsonProperty("data")
private List<EmpSearch> data;
}
EmpSearch
public class EmpSearch implements java.io.Serializable {
private static final long serialVersionUID = -7665557350420327753L;
@JsonProperty("divisionDesc")
private String divisionDesc;
@JsonProperty("corpId")
private String corpId;
@JsonProperty("businessUnitDesc")
private String businessUnitDesc;
@JsonProperty("fdirName")
private String fdirName;
}
如果数据列表(List data;)包含500条记录-此服务将在2秒钟后返回
但是,如果它包含大约2000条记录(这是一种常见用例),则最多可能需要2分钟才能返回
根据我的日志语句-从数据库返回此数据大约需要2秒钟,其余时间用于生成json。
我正在使用Spring Web版本4.3.3.RELEASE。
从调试日志中,我可以看到它正在使用类org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
谁能提供任何建议以帮助我成功完成大量json数据的处理?
最佳答案
决定重构代码以不返回太多json数据。
根据问题反馈尝试了多个建议,但未获得要求的收益