在几秒钟内从 Spring MVC 中的表中获取 400K 数据

我正在使用 Spring MVC,我需要获得的不仅仅是400k datas我在 mysql 查询中使用 JOIN 的表。


我实际上拥有的是一个控制器,它返回包含一个列表。我使用 AJAX 调用控制器。


我的解决方案的问题是我无法在几秒钟内获取 List 的数据,在 JSP 页面上加载需要超过 5 分钟。


在页面 Jquery..


$(document).ready(function ajaxPost() {

  $.ajax({

      type: "GET",

  data: page,

      url: "allListAjax",

      success: function(list) {

        //here i get responce list and page which takes 5 minutes

  }//success

 }//ajax

}//ready

在控制器中..


@RequestMapping(value="/allListAjax")

public @ResponseBody IVRRouteReportWrapper dashoardAjax(Model model, @RequestParam(required = false) Integer page) {

    IVRRouteReportWrapper wrappObj= new IVRRouteReportWrapper();

    List<IVRRouteReport> list = ivrRouteServiceInterface.getAllIVRRouteReport(page);

wrappObj.setIVRouteReportList(list);

    wrappObj.setPage(page);

return wrappObj;

}

这里,IVRRouteReportWrapper是一个域模型,其中包含 List 和 page 的 setter 和 getter。


在服务实施中...


 public List<IVRRouteReport> getAllIVRRouteReport(Integer page) {

      return ivrRouteDAOInterface.getAllIVRRouteReport(page);

    }

在道实现中...


public List<IVRRouteReport> getAllIVRRouteReport(Integer page) {

if(page==null) {

    page = 0;

}else {

    page = page*200;

}

String strqry= "SELECT c.caller_id_number as caller_id_number, c.destination_number as destination_number,"

        +" c.created_time as created_time, vbDtmf.digit as dtmf FROM VoiceBroadcastDTMF vbDtmf "

        +"LEFT JOIN cdr c ON vbDtmf.uuid=c.orig_id ORDER BY c.created_time DESC";


Query query = getSession().createSQLQuery(strqry)

              .addScalar("caller_id_number", new StringType())

              .addScalar("destination_number", new StringType())

              .addScalar("created_time", new StringType())

              .addScalar("dtmf", new StringType())

              .setResultTransformer(Transformers.aliasToBean(IVRRouteReport.class))

              .setFirstResult(page)

              .setMaxResults(200);


 List<IVRRouteReport> ivrRouteReportList =(List<IVRRouteReport>) query.getResultList();

 getSession().flush();

 return ivrRouteReportList;

 }

有没有办法在 jsp 页面上快速返回这个列表?提前致谢。


眼眸繁星
浏览 112回答 2
2回答

蝴蝶不菲

索引“created_time”列,并通过仅指定查询中的必填字段来省略不需要的字段,如下所示String&nbsp;strqry=&nbsp;"SELECT&nbsp;c.caller_id_number&nbsp;as&nbsp;caller_id_number,&nbsp;c.destination_number&nbsp;as&nbsp;destination_number," &nbsp;&nbsp;&nbsp;&nbsp;+"&nbsp;c.created_time&nbsp;as&nbsp;created_time,&nbsp;vbDtmf.digit&nbsp;as&nbsp;dtmf&nbsp;FROM&nbsp;VoiceBroadcastDTMF&nbsp;vbDtmf&nbsp;" &nbsp;&nbsp;&nbsp;&nbsp;+"LEFT&nbsp;JOIN&nbsp;(SELECT&nbsp;caller_id_number&nbsp;,&nbsp;destination_number&nbsp;,&nbsp;created_time&nbsp;FROM&nbsp;cdr)&nbsp;as&nbsp;c&nbsp;ON&nbsp;vbDtmf.uuid=c.orig_id&nbsp;ORDER&nbsp;BY&nbsp;c.created_time&nbsp;DESC";

侃侃无极

去分页。参考spring-mvc-pagination
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java