…Mapper.xml中统计代码:
略写
//返回结果对象resultType和parameterType都是hashMap对象
<select id="queryStatistic" resultType="java.util.Map"
parameterType="java.util.HashMap">
SELECT SUM(DATA_SIZE) collectionNum,
COUNT(BATCH_ID) collectionDispatch,
SUM(COLLECT_TIME) collectionDuration,
COUNT(COLLECT_CYC) collectionAlarm
FROM tableName
</select>
…controller.java中代码:
@RequestMapping("/list1")
@ResponseBody
public R list1(@RequestParam Map<String, Object> params) {
//返回的是map对象,key是string类型,value是Integer类型
Map<String, Integer> statisticList = tbCollectBatchService.queryStatistic(params);
R r = R.ok(); //R是自定义hashMap实体类
r.put("statisticList", statisticList);
return r;
}
…jsp中jquery和ajax代码:
$.ajax({
url : '${basePath}/source/list1.action',//controller中的方法
type : 'GET',
data : {
"id" : id,
"startTime" : startTime,
"endTime" : endTime
},//作为条件的传入参数
datatype : "json",
success : function(data) {
//{COLLECTIONNUM=2000000, COLLECTIONALARM=2, COLLECTIONDISPATCH=2, COLLECTIONDURATION=120}
var collectionNum0 = parseInt(data.statisticList.COLLECTIONNUM);//controller中返回的statisticList对象中各个参数名称,为避免写错,最好调试看看
var collectionDispatch0 = parseInt(data.statisticList.COLLECTIONDISPATCH);
var collectionDuration0 = parseInt(data.statisticList.COLLECTIONDURATION);
var collectionAlarm0 = parseInt(data.statisticList.COLLECTIONALARM);
$("#collectionNum0").html(collectionNum);
$("#collectionDispatch0").html(collectionDispatch);
$("#collectionDuration0").html(collectionDuration);
$("#collectionAlarm0").html(collectionAlarm);
}
});