嵌套并且列名动态取值

<c:forEach items="${datas}" var="item" varStatus="stat">
<dataset seriesName="${item.ORG_NAME}">
<c:forEach items="${column_name}" var="column">
<set value='${item[column] }'/>
</c:forEach>
       </dataset>
</c:forEach>

后台动态组装列名,然后存储在column_name数组中。datas为查询所有记录的数组。
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			
			Calendar call = Calendar.getInstance();
			query.setEndDate( new DateUtils(cal).toDateString());
			Date date1 = sdf.parse(query.getEndDate());
			call.setTime(date1);
			int year1 = call.get(call.YEAR);
			int month1 = call.get(call.MONTH) + 1;
			
			cal.set(Calendar.DAY_OF_MONTH, 1);
			cal.add(Calendar.MONTH, -2);
			query.setBeginDate(new DateUtils(cal).toDateString());
			
			Date date2 = sdf.parse(query.getBeginDate());
			call.setTime(date2);
			int year2 = call.get(call.YEAR);
			int month2 = call.get(call.MONTH) + 1;
			List column_name = new ArrayList();
			String str = "";
			if(year1 == year2){
				for(int i = month2; i <= month1; i++){
					months.add(i);
					str += "SUM( CASE WHEN  MONTH = '0"+i+"' THEN NUM ELSE 0 END ) MONTH"+i+",";
					column_name.add("MONTH"+i);
				}
			}

request.setAttribute("column_name", column_name);
			query.setDynamicSql(str);
List datas = commonService.getObjects(querySql, query);
		request.setAttribute("datas", datas);
		request.setAttribute("months", months);
		if(datas != null){
			request.setAttribute("totalRows", datas.size());
		}


查询指定时间段内,每个月的感染病毒数 作为列显示

你可能感兴趣的:(foreach)