我正在使用 Spring MVC,我需要通过我的表获取超过 400k 数据
,其中我还在 mysql 查询中使用 JOIN。
我实际上拥有的是一个返回包含列表的 Controller 。我使用 AJAX 调用 Controller 。
我的解决方案的问题是我无法在几秒钟内获取 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
在 Controller 中..
@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
是一个Domain模型,其中包含List和页面的setter和getter。
服务实现中...
public List<IVRRouteReport> getAllIVRRouteReport(Integer page) {
return ivrRouteDAOInterface.getAllIVRRouteReport(page);
}
在 Dao 实现中...
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;
}
Is there any way to return this List Fast on jsp page ? Thanks in advance.
最佳答案
为“created_time”列建立索引,并通过在查询中仅指定必填字段来省略非必填字段,如下所示
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 (SELECT caller_id_number , destination_number , created_time FROM cdr) as c ON vbDtmf.uuid=c.orig_id ORDER BY c.created_time DESC";
关于java - 在几秒钟内从 Spring MVC 中的表中获取 400K 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55036144/