簡體   English   中英

Spring並返回大量的Json數據

[英]Spring and returning large volume of Json data

我的項目基於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;

}

如果數據列表(列表數據;)包含500條記錄 - 此服務在大約2秒內返回但是如果它包含大約2000條記錄(這是一個常見的用例),則最多可能需要2分鍾才能返回

基於我的日志語句 - 從數據庫返回此數據大約需要2秒鍾,剩下的時間用於生成json。

我正在使用Spring Web版本4.3.3.RELEASE。 從調試日志我可以看到它正在使用類org.springframework.http.converter.json.MappingJackson2HttpMessageConverter

任何人都可以提供任何建議,我需要做什么才能成功渲染大量的json數據?

決定重構代碼以不返回盡可能多的json數據。 根據問題反饋嘗試了多項建議,但未獲得所需的收益

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM