jasperserver 创建带查询的报表

来源:互联网 发布:免费动画视频制作软件 编辑:程序博客网 时间:2024/05/09 19:02

在jasper server上创建带参数的查询报表,在国外的论坛上才找到解决方案。


创建实体bean

package example.cds;public class ReportOneBean{private String name;//申请人名称private String userId;//申请人IDprivate String organization; //人员组织机构private String bizRoleCode;  //岗位IDprivate String bizRoleName;  //岗位名称private String resource;   //业务系统private String itRoleCode;  //授权角色idprivate String itRoleName;  //授权角色private String orgScope;     private String productScope;  private String resourceScope; private String zhangTaoScope; //账户维度private String approveName;   //审批人private String approveReason; //审批意见private String createTime;//申请时间private String processId;//任务编码public ReportOneBean(String name, String userId, String organization,String bizRoleCode, String bizRoleName, String resource,String itRoleCode, String itRoleName, String orgScope,String productScope, String resourceScope, String zhangTaoScope,String approveName, String approveReason, String createTime,String processId) {this.name = name;this.userId = userId;this.organization = organization;this.bizRoleCode = bizRoleCode;this.bizRoleName = bizRoleName;this.resource = resource;this.itRoleCode = itRoleCode;this.itRoleName = itRoleName;this.orgScope = orgScope;this.productScope = productScope;this.resourceScope = resourceScope;this.zhangTaoScope = zhangTaoScope;this.approveName = approveName;this.approveReason = approveReason;this.createTime = createTime;this.processId = processId;} public ReportOneBean() {// TODO Auto-generated constructor stub}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getUserId() {return userId;}public void setUserId(String userId) {this.userId = userId;}public String getOrganization() {return organization;}public void setOrganization(String organization) {this.organization = organization;}public String getBizRoleCode() {return bizRoleCode;}public void setBizRoleCode(String bizRoleCode) {this.bizRoleCode = bizRoleCode;}public String getBizRoleName() {return bizRoleName;}public void setBizRoleName(String bizRoleName) {this.bizRoleName = bizRoleName;}public String getResource() {return resource;}public void setResource(String resource) {this.resource = resource;}public String getItRoleCode() {return itRoleCode;}public void setItRoleCode(String itRoleCode) {this.itRoleCode = itRoleCode;}public String getItRoleName() {return itRoleName;}public void setItRoleName(String itRoleName) {this.itRoleName = itRoleName;}public String getOrgScope() {return orgScope;}public void setOrgScope(String orgScope) {this.orgScope = orgScope;}public String getProductScope() {return productScope;}public void setProductScope(String productScope) {this.productScope = productScope;}public String getResourceScope() {return resourceScope;}public void setResourceScope(String resourceScope) {this.resourceScope = resourceScope;}public String getZhangTaoScope() {return zhangTaoScope;}public void setZhangTaoScope(String zhangTaoScope) {this.zhangTaoScope = zhangTaoScope;}public String getApproveName() {return approveName;}public void setApproveName(String approveName) {this.approveName = approveName;}public String getApproveReason() {return approveReason;}public void setApproveReason(String approveReason) {this.approveReason = approveReason;}public String getCreateTime() {return createTime;}public void setCreateTime(String createTime) {this.createTime = createTime;}public String getProcessId() {return processId;}public void setProcessId(String processId) {this.processId = processId;}}

创建查询service

package example.cds;import java.util.HashMap;import java.util.Map;import com.jaspersoft.jasperserver.api.metadata.jasperreports.service.ReportDataSourceService;import net.sf.jasperreports.engine.JRDataSource;import net.sf.jasperreports.engine.JRDataset;import net.sf.jasperreports.engine.JRException;import net.sf.jasperreports.engine.query.JRAbstractQueryExecuter;public class ReportOneQueryExecuter extends JRAbstractQueryExecuter{private String startTime;private String endTime;private String reportType;/** * @param dataset * @param parameters */public ReportOneQueryExecuter(JRDataset dataset, Map parameters) {super(dataset, parameters);parseQuery();}public boolean cancelQuery() throws JRException {return false;}public void close() {}public JRDataSource createDatasource() throws JRException {String[] times = getQueryString().trim().split(",");JRDataSource jd = null;startTime =times[0];if (times.length > 1) {endTime = times[1];}if (times.length > 1) {reportType = times[2];}Map map = new HashMap();System.out.println("---startTime-------"+startTime+"--endTime="+endTime+"-----reportType------"+reportType);if("two".equals(reportType)){jd=new ReportTwoDataSource(startTime,endTime, map);}else if("three".equals(reportType)){jd=new ReportThreeDataSource(startTime,endTime,map);}else if("four".equals(reportType)){jd=new ReportFourDataSource(startTime,endTime, map);}else if("five".equals(reportType)){jd=new ReportFiveDataSource(startTime,endTime, map);}else{jd=new ReportOneDataSource(startTime,endTime, map);}return jd ;}protected String getParameterReplacement(String parameterName) {return null;}}

查询factory

package example.cds;import java.util.Map;import com.jaspersoft.jasperserver.api.metadata.jasperreports.service.ReportDataSourceService;import net.sf.jasperreports.engine.JRDataset;import net.sf.jasperreports.engine.JRException;import net.sf.jasperreports.engine.query.JRQueryExecuter;import net.sf.jasperreports.engine.query.JRQueryExecuterFactory;public class ReportOneQueryExecuterFactory implements JRQueryExecuterFactory {private static final Object[] BUILTIN_PARAMETERS = { "reportonequery", String.class };public JRQueryExecuter createQueryExecuter(JRDataset dataset, Map parameters)throws JRException {System.out.println("------------------ReportOneQueryExecuterFactory---------");return new ReportOneQueryExecuter(dataset, parameters);}public Object[] getBuiltinParameters() {return BUILTIN_PARAMETERS;}public boolean supportsQueryParameterType(String className) {return true;}}

dataSource

package example.cds;import java.util.ArrayList;import java.util.List;import java.util.Map;import net.sf.jasperreports.engine.JRDataSource;import net.sf.jasperreports.engine.JRException;import net.sf.jasperreports.engine.JRField;public class ReportOneDataSource implements JRDataSource {private int index = -1;private String startTime;private String endTime;JRDataSource dataSource;DealReportOneData reportData = new DealReportOneData();List<ReportOneBean> list = new ArrayList<ReportOneBean>();/** * @param startTime、endTime * @param parameterValues  */public ReportOneDataSource(String startTime,String endTime,  Map parameterValues) {this.startTime = startTime;this.endTime = endTime;list =reportData.outBizPrivilegeReportOne(CommonUtil.dateConvert(startTime),CommonUtil.dateConvert(endTime));}/* * (non-Javadoc) *  * @see net.sf.jasperreports.engine.JRDataSource#getFieldValue(net.sf.jasperreports.engine.JRField) */public Object getFieldValue(JRField jrField) throws JRException {System.out.println("--------------getFieldValue-------------------");Object value = null;String fieldName = jrField.getName();ReportOneBean oneBean = list.get(index);if ("name".equals(fieldName)) {value = oneBean.getName();} else if ("userId".equals(fieldName)) {value = oneBean.getUserId();}else if ("organization".equals(fieldName)) {value = oneBean.getOrganization();}else if ("bizRoleCode".equals(fieldName)) {value = oneBean.getBizRoleCode();}else if ("bizRoleName".equals(fieldName)) {value = oneBean.getBizRoleName();}else if ("resource".equals(fieldName)) {value = oneBean.getResource();}else if ("itRoleCode".equals(fieldName)) {value = oneBean.getItRoleCode();}else if ("itRoleName".equals(fieldName)) {value = oneBean.getItRoleName();}else if ("orgScope".equals(fieldName)) {value = oneBean.getOrgScope();}else if ("productScope".equals(fieldName)) {value = oneBean.getProductScope();}else if ("resourceScope".equals(fieldName)) {value = oneBean.getResourceScope();}else if ("zhangTaoScope".equals(fieldName)) {value = oneBean.getZhangTaoScope();}else if ("approveName".equals(fieldName)) {value = oneBean.getApproveName();}else if ("approveReason".equals(fieldName)) {value = oneBean.getApproveReason();}else if ("createTime".equals(fieldName)) {try {if(oneBean.getCreateTime()!=null){value = CommonUtil.format(Long.valueOf(oneBean.getCreateTime()));}else{value="";}} finally {}} else if ("processId".equals(fieldName)) {value = oneBean.getProcessId();}return value;}/* *  * @see net.sf.jasperreports.engine.JRDataSource#next() */public boolean next() throws JRException {System.out.println("--------------Next-------------------"+list.size());index++;return (index < list.size());}}
list =reportData.outBizPrivilegeReportOne(CommonUtil.dateConvert(startTime),CommonUtil.dateConvert(endTime));是获取报表数据,报表数据来源是查询oracle数据库。

jxml文件,红色字体部分是查询条件,language也要和配置文件(jasperreports.properties)一样。

<?xml version="1.0" encoding="UTF-8"?><jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="ssfReportOne" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="51c54b63-0cd1-4b4a-a26d-c95878cad34c"><property name="ireport.zoom" value="1.0"/><property name="ireport.x" value="0"/><property name="ireport.y" value="0"/><parameter name="startTime" class="java.util.Date"/><parameter name="endTime" class="java.util.Date"/><queryString language="reportonequery"><span style="color:#ff6666;"><![CDATA[$P!{startTime},$P!{endTime}]]></span></queryString><field name="resource" class="java.lang.String"><fieldDescription><![CDATA[resource]]></fieldDescription></field><field name="bizRoleCode" class="java.lang.String"><fieldDescription><![CDATA[bizRoleCode]]></fieldDescription></field><field name="resourceScope" class="java.lang.String"><fieldDescription><![CDATA[resourceScope]]></fieldDescription></field><field name="organization" class="java.lang.String"><fieldDescription><![CDATA[organization]]></fieldDescription></field><field name="bizRoleName" class="java.lang.String"><fieldDescription><![CDATA[bizRoleName]]></fieldDescription></field><field name="zhangTaoScope" class="java.lang.String"><fieldDescription><![CDATA[zhangTaoScope]]></fieldDescription></field><field name="name" class="java.lang.String"><fieldDescription><![CDATA[name]]></fieldDescription></field><field name="approveName" class="java.lang.String"><fieldDescription><![CDATA[approveName]]></fieldDescription></field><field name="createTime" class="java.lang.String"><fieldDescription><![CDATA[createTime]]></fieldDescription></field><field name="productScope" class="java.lang.String"><fieldDescription><![CDATA[productScope]]></fieldDescription></field><field name="itRoleCode" class="java.lang.String"><fieldDescription><![CDATA[itRoleCode]]></fieldDescription></field><field name="userId" class="java.lang.String"><fieldDescription><![CDATA[userId]]></fieldDescription></field><field name="approveReason" class="java.lang.String"><fieldDescription><![CDATA[approveReason]]></fieldDescription></field><field name="itRoleName" class="java.lang.String"><fieldDescription><![CDATA[itRoleName]]></fieldDescription></field><field name="orgScope" class="java.lang.String"><fieldDescription><![CDATA[orgScope]]></fieldDescription></field><field name="processId" class="java.lang.String"><fieldDescription><![CDATA[processId]]></fieldDescription></field><title><band height="28" splitType="Stretch"><staticText><reportElement x="226" y="4" width="113" height="20" uuid="dfa42efc-0bf0-4afe-a1d8-da51fe51a327"/><textElement><font size="12" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/></textElement><text><![CDATA[标准外授权清单报表]]></text></staticText></band></title><columnHeader><band height="43" splitType="Stretch"><staticText><reportElement x="3" y="1" width="26" height="39" uuid="e5d2fe80-aba1-48fa-aad7-4fd437afd837"/><box topPadding="1" leftPadding="1" bottomPadding="1" rightPadding="1"><pen lineWidth="0.25"/><topPen lineWidth="0.25"/><leftPen lineWidth="0.25"/><bottomPen lineWidth="0.25"/><rightPen lineWidth="0.25"/></box><textElement><font pdfFontName="STSong-Light" pdfEncoding="UniCNS-UCS2-H" isPdfEmbedded="true"/></textElement><text><![CDATA[姓名]]></text></staticText><staticText><reportElement x="34" y="1" width="26" height="39" uuid="5df299f6-f881-4f07-9ae0-9c3ddb8a41a9"/><box topPadding="1" leftPadding="1" bottomPadding="1" rightPadding="1"><pen lineWidth="0.25"/><topPen lineWidth="0.25"/><leftPen lineWidth="0.25"/><bottomPen lineWidth="0.25"/><rightPen lineWidth="0.25"/></box><textElement><font pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/></textElement><text><![CDATA[用户ID]]></text></staticText><staticText><reportElement x="65" y="1" width="26" height="39" uuid="cad3dd57-355b-44af-b806-a82280ef4e1c"/><box topPadding="1" leftPadding="1" bottomPadding="1" rightPadding="1"><pen lineWidth="0.25"/><topPen lineWidth="0.25"/><leftPen lineWidth="0.25"/><bottomPen lineWidth="0.25"/><rightPen lineWidth="0.25"/></box><textElement><font pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/></textElement><text><![CDATA[组织]]></text></staticText><staticText><reportElement x="96" y="1" width="26" height="39" uuid="8e7d376c-5891-48b9-9e16-23e3f6762db3"/><box topPadding="1" leftPadding="1" bottomPadding="1" rightPadding="1"><pen lineWidth="0.25"/><topPen lineWidth="0.25"/><leftPen lineWidth="0.25"/><bottomPen lineWidth="0.25"/><rightPen lineWidth="0.25"/></box><textElement><font pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/></textElement><text><![CDATA[岗位ID]]></text></staticText><staticText><reportElement x="127" y="1" width="26" height="39" uuid="e1bf60ea-623a-4c68-a96d-b946fda26ce9"/><box topPadding="1" leftPadding="1" bottomPadding="1" rightPadding="1"><pen lineWidth="0.25"/><topPen lineWidth="0.25"/><leftPen lineWidth="0.25"/><bottomPen lineWidth="0.25"/><rightPen lineWidth="0.25"/></box><textElement><font pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/></textElement><text><![CDATA[岗位名称]]></text></staticText><staticText><reportElement x="158" y="1" width="26" height="39" uuid="b93b3c37-2b54-4384-ac3b-48e21862ba5c"/><box topPadding="1" leftPadding="1" bottomPadding="1" rightPadding="1"><pen lineWidth="0.25"/><topPen lineWidth="0.25"/><leftPen lineWidth="0.25"/><bottomPen lineWidth="0.25"/><rightPen lineWidth="0.25"/></box><textElement><font pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/></textElement><text><![CDATA[业务系统]]></text></staticText><staticText><reportElement x="189" y="1" width="37" height="39" uuid="79daa9a4-6bcd-43f5-b735-8382bde3a912"/><box topPadding="1" leftPadding="1" bottomPadding="1" rightPadding="1"><pen lineWidth="0.25"/><topPen lineWidth="0.25"/><leftPen lineWidth="0.25"/><bottomPen lineWidth="0.25"/><rightPen lineWidth="0.25"/></box><textElement><font pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/></textElement><text><![CDATA[授权角色id]]></text></staticText><staticText><reportElement x="232" y="1" width="45" height="39" uuid="cbc6fba0-c887-462b-83b1-eebfdd0bb060"/><box topPadding="1" leftPadding="1" bottomPadding="1" rightPadding="1"><pen lineWidth="0.25"/><topPen lineWidth="0.25"/><leftPen lineWidth="0.25"/><bottomPen lineWidth="0.25"/><rightPen lineWidth="0.25"/></box><textElement><font pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/></textElement><text><![CDATA[授权角色]]></text></staticText><staticText><reportElement x="281" y="1" width="26" height="39" uuid="1b3493fa-cd9a-4a29-b24b-2ec15c8afdc4"/><box topPadding="1" leftPadding="1" bottomPadding="1" rightPadding="1"><pen lineWidth="0.25"/><topPen lineWidth="0.25"/><leftPen lineWidth="0.25"/><bottomPen lineWidth="0.25"/><rightPen lineWidth="0.25"/></box><textElement><font pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/></textElement><text><![CDATA[机构维度]]></text></staticText><staticText><reportElement x="312" y="1" width="26" height="39" uuid="4aa62d7d-f86b-4d62-9d20-cb336df8034e"/><box topPadding="1" leftPadding="1" bottomPadding="1" rightPadding="1"><pen lineWidth="0.25"/><topPen lineWidth="0.25"/><leftPen lineWidth="0.25"/><bottomPen lineWidth="0.25"/><rightPen lineWidth="0.25"/></box><textElement><font pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/></textElement><text><![CDATA[产品维度]]></text></staticText><staticText><reportElement x="343" y="1" width="26" height="39" uuid="de56fde4-1bcc-4881-b1d8-b9f527b626a7"/><box topPadding="1" leftPadding="1" bottomPadding="1" rightPadding="1"><pen lineWidth="0.25"/><topPen lineWidth="0.25"/><leftPen lineWidth="0.25"/><bottomPen lineWidth="0.25"/><rightPen lineWidth="0.25"/></box><textElement><font pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/></textElement><text><![CDATA[系统维度]]></text></staticText><staticText><reportElement x="374" y="1" width="26" height="39" uuid="549c1a33-31b6-42ce-892c-cc4ea33ba579"/><box topPadding="1" leftPadding="1" bottomPadding="1" rightPadding="1"><pen lineWidth="0.25"/><topPen lineWidth="0.25"/><leftPen lineWidth="0.25"/><bottomPen lineWidth="0.25"/><rightPen lineWidth="0.25"/></box><textElement><font pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/></textElement><text><![CDATA[账户维度]]></text></staticText><staticText><reportElement x="405" y="1" width="26" height="39" uuid="864a75f6-72ac-44b4-ad13-34aa86cbeb9e"/><box topPadding="1" leftPadding="1" bottomPadding="1" rightPadding="1"><pen lineWidth="0.25"/><topPen lineWidth="0.25"/><leftPen lineWidth="0.25"/><bottomPen lineWidth="0.25"/><rightPen lineWidth="0.25"/></box><textElement><font pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/></textElement><text><![CDATA[审批人]]></text></staticText><staticText><reportElement x="436" y="1" width="36" height="39" uuid="37ac52f8-ffa1-4f35-8fba-70e523cb2fe7"/><box topPadding="1" leftPadding="1" bottomPadding="1" rightPadding="1"><pen lineWidth="0.25"/><topPen lineWidth="0.25"/><leftPen lineWidth="0.25"/><bottomPen lineWidth="0.25"/><rightPen lineWidth="0.25"/></box><textElement><font pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/></textElement><text><![CDATA[审批意见]]></text></staticText><staticText><reportElement mode="Transparent" x="475" y="1" width="48" height="39" uuid="d324f963-ad3c-44a8-86c0-e24b2d93ca31"/><box topPadding="1" leftPadding="1" bottomPadding="1" rightPadding="1"><pen lineWidth="0.25"/><topPen lineWidth="0.25"/><leftPen lineWidth="0.25"/><bottomPen lineWidth="0.25"/><rightPen lineWidth="0.25"/></box><textElement><font pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/></textElement><text><![CDATA[创建时间]]></text></staticText><staticText><reportElement x="527" y="1" width="26" height="39" uuid="9803e6f8-4244-4c86-8eb8-79b4d1b2df8a"/><box topPadding="1" leftPadding="1" bottomPadding="1" rightPadding="1"><pen lineWidth="0.25"/><topPen lineWidth="0.25"/><leftPen lineWidth="0.25"/><bottomPen lineWidth="0.25"/><rightPen lineWidth="0.25"/></box><textElement><font pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/></textElement><text><![CDATA[任务编码]]></text></staticText></band></columnHeader><detail><band height="54" splitType="Stretch"><textField isBlankWhenNull="true"><reportElement stretchType="RelativeToBandHeight" x="2" y="6" width="25" height="40" backcolor="#FFFFFF" uuid="85f4f9e5-d9da-4ced-bd20-a7e648e320c4"/><textElement><font pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/></textElement><textFieldExpression><![CDATA[$F{name}]]></textFieldExpression></textField><textField><reportElement stretchType="RelativeToBandHeight" x="32" y="6" width="25" height="40" uuid="98417d60-2847-41e2-ad4b-e1ffad78c9cc"/><textElement><font pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/></textElement><textFieldExpression><![CDATA[$F{userId}]]></textFieldExpression></textField><textField><reportElement stretchType="RelativeToBandHeight" x="62" y="6" width="25" height="40" uuid="2e0dd1ad-92f7-43f6-b8a9-c5f16ab623f5"/><textElement><font pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/></textElement><textFieldExpression><![CDATA[$F{organization}]]></textFieldExpression></textField><textField><reportElement stretchType="RelativeToBandHeight" x="97" y="6" width="25" height="40" uuid="5cb4d681-d3e4-436b-94f3-830251601b62"/><textElement><font pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/></textElement><textFieldExpression><![CDATA[$F{bizRoleCode}]]></textFieldExpression></textField><textField><reportElement stretchType="RelativeToBandHeight" x="128" y="6" width="25" height="40" uuid="5dc75649-b919-428c-8450-ac61d5f6d77e"/><textElement><font pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/></textElement><textFieldExpression><![CDATA[$F{bizRoleName}]]></textFieldExpression></textField><textField><reportElement stretchType="RelativeToBandHeight" x="158" y="6" width="25" height="40" uuid="e848096e-5c3d-4a0c-8ac4-a75679de0ebc"/><textElement><font pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/></textElement><textFieldExpression><![CDATA[$F{resource}]]></textFieldExpression></textField><textField><reportElement stretchType="RelativeToBandHeight" x="189" y="6" width="37" height="40" uuid="793b6b3a-22e3-4e82-994c-3efd43213add"/><textElement><font pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/></textElement><textFieldExpression><![CDATA[$F{itRoleCode}]]></textFieldExpression></textField><textField><reportElement stretchType="RelativeToBandHeight" x="232" y="6" width="45" height="40" uuid="cb2bbdac-5e1e-440b-9551-76ad4927bab5"/><textElement><font pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/></textElement><textFieldExpression><![CDATA[$F{itRoleName}]]></textFieldExpression></textField><textField><reportElement stretchType="RelativeToBandHeight" x="281" y="6" width="25" height="40" uuid="a90ab20e-1bd4-4f3d-b32a-4dcfb0df39c4"/><textElement><font pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/></textElement><textFieldExpression><![CDATA[$F{orgScope}]]></textFieldExpression></textField><textField><reportElement stretchType="RelativeToBandHeight" x="313" y="6" width="25" height="40" uuid="4c7bb69b-c2ba-4f98-b2f6-7cac057d2015"/><textElement><font pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/></textElement><textFieldExpression><![CDATA[$F{productScope}]]></textFieldExpression></textField><textField><reportElement stretchType="RelativeToBandHeight" x="343" y="6" width="28" height="40" uuid="bd9064e5-80e8-4d79-a74a-3bc209bc44d6"/><textElement><font pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/></textElement><textFieldExpression><![CDATA[$F{resourceScope}]]></textFieldExpression></textField><textField><reportElement stretchType="RelativeToBandHeight" x="375" y="6" width="25" height="40" uuid="25d7dd75-60cc-4ca8-a0b8-763fddfab0d2"/><textElement><font pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/></textElement><textFieldExpression><![CDATA[$F{zhangTaoScope}]]></textFieldExpression></textField><textField><reportElement stretchType="RelativeToBandHeight" x="405" y="6" width="26" height="40" uuid="7367d21a-d184-499d-b7e9-39404331ef45"/><textElement><font pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/></textElement><textFieldExpression><![CDATA[$F{approveName}]]></textFieldExpression></textField><textField><reportElement stretchType="RelativeToBandHeight" x="436" y="6" width="36" height="40" uuid="a4ff20e9-c335-4770-b3c5-40bad36df60a"/><textElement><font pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/></textElement><textFieldExpression><![CDATA[$F{approveReason}]]></textFieldExpression></textField><textField><reportElement stretchType="RelativeToBandHeight" x="527" y="6" width="25" height="40" uuid="cadc3a24-260c-4fba-bc42-fcb0a1ef331e"/><textElement><font pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/></textElement><textFieldExpression><![CDATA[$F{processId}]]></textFieldExpression></textField><line><reportElement x="1" y="-2" width="553" height="1" uuid="2e654777-c239-4094-b55d-acdcce360619"/></line><textField><reportElement x="475" y="6" width="48" height="40" uuid="4c555045-55a2-4001-b386-97f39e7f6913"/><textElement><font pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/></textElement><textFieldExpression><![CDATA[$F{createTime}]]></textFieldExpression></textField></band></detail><columnFooter><band height="45" splitType="Stretch"/></columnFooter></jasperReport>

applicationContext-reportCustomSoure.xml(这个文件要放到 jasperserver 部署的tomcat目录下。位置是:Jaspersoft6\apache-tomcat\webapps\jasperserver\WEB-INF

<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">        <!-- define a custom data source --><bean id="reportCustomSource" class="com.jaspersoft.jasperserver.api.engine.jasperreports.util.CustomDataSourceDefinition"><!-- this prop is always the same; it registers the custom ds --><property name="factory" ref="customDataSourceServiceFactory"/><!-- name used in message catalog and elsewhere --><property name="name" value="reportCustomSource"/><!-- class name of implementation --><property name="serviceClassName" value="example.cds.ReportOneDataSourceService"/>   <property name="validator"><bean class="example.cds.ReportOneDataSourceValidator"/></property><property name="queryExecuterMap"><map><entry key="reportonequery" value="example.cds.ReportOneQueryExecuterFactory"/></map></property><property name="propertyDefinitions"><list><map><entry key="name" value="<span style="color:#ff6666;">startTime</span>"/></map><map><entry key="name" value="<span style="color:#ff9966;">endTime</span>"/></map></list></property></bean><!-- add your message catalog -->    <bean class="com.jaspersoft.jasperserver.api.common.util.spring.GenericBeanUpdater">        <property name="definition" ref="addMessageCatalog"/>        <property name="value">            <list>                <value>WEB-INF/bundles/reportCustomSource</value>            </list>        </property>        <property name="valueType" value="stringList"/>    </bean></beans>
参数要与jmxl文件中的一致。

这些配置完成以后剩下的就需要把jar文件放到lib目录下,然后通过jasperserver创建report

1 0
原创粉丝点击