海量数据的清单式列表在读取、展现及导出过程中可能会出现速度过慢、内存溢出、系统死机等问题,分页计算extHtml标签扩展了原html标签的功能,实现了以页为单位对数据进行读取和展现及导出等操作,大大降低了内存占有量,提高了运行效率,避免内存溢出等问题。
分页标签的写法大致为:
<report:extHtml
name="report1"
reportFileName="api/1.6.raq"
totalCountExp="query('SELECT count(*) FROM 订单明细')"
params="<%=param.toString()%>"
scale="1.1"
pageCount="10"
needPageMark="yes"
funcBarFontFace="黑体"
funcBarFontSize="14"
funcBarFontColor="red"
functionBarColor="#FFCCFF"
separator="|"
needSaveAsExcel="yes"
needSaveAsPdf="yes"
needSaveAsWord="yes"
funcBarLocation="top"
needPrint="yes"
firstPageLabel="首页"
prevPageLabel="前一页"
nextPageLabel="后一页"
lastPageLabel="尾页"
printLabel="全打印"
excelLabel="导出excel"
pdfLabel="导出pdf"
wordLabel="导出word"
generateParamForm="yes"
displayNoLinkPageMark="yes"
saveAsName="测试"
startRowParamName="startRow" //起始行参数名,非必填,默认值为startRow
endRowParamName="endRow" //结束行参数名,非必填,默认值为endRow
userFuncBarElements="<a href='http://www.runqian.com.cn'>润乾</a>"
needScroll="no"
scrollHeight="100"
needLinkStyle="yes"
exceptionPage="myErrorPage.jsp"
/>
从上面我们可以看到,这里的totalCountExp属性是写死的,如果想写一个通用jsp,如何来动态设置总记录的表达式呢?
我们可以先在报表里建立一个数据集,这个数据集的sql就是查询总记录条数的,那么,这个数据集就可以在设计报表模版的时候就写好:
这样我们就可以在加载报表模版的时候,把这个sql从报表模版里面读取出来,并设置到里面分页标签里面去:
import com.runqian.report4.model.ReportDefine;import com.runqian.report4.usermodel.DataSetConfig;import com.runqian.report4.usermodel.SQLDataSetConfig;import com.runqian.report4.util.ReportUtils;public class sqlReadOut {/*** @param args* @throws Exception*/public static void main(String[] args) throws Exception {// 读取报表模版定义ReportDefine rd = (ReportDefine)ReportUtils.read("C:\\Program Files\\reportHome\\webapps\\demo\\reportFiles\\初级教程\\3.3.raq");//取报表模版第一个数据集的对象SQLDataSetConfig sdc = (SQLDataSetConfig)rd.getDataSetMetaData().getDataSetConfig(1);//得到sqlString sql = sdc.getSQL();System.out.println(sql);}}
我们获得sql后,可以传递到前台页面,再接收:
String sql = request.getParameter( "sql" );
<report:extHtml name="report1" reportFileName="api/1.6.raq" //报表名,必填属性 totalCountExp="<%=sql%>" //总记录数,必填属性 //其值为一个润乾的非数据集函数,返回整型数据。如用query执行一个count的sql。 />
用同样的方法,还可以设置标签中的其他属性,这样就可以根据不同的报表模版来动态的设置标签的属性了.