jasperserver 創建帶查詢的報表

在jasper server上創建帶參數的查詢報表,在國外的論壇上才找到解決方案。


創建實體bean

package example.cds;


public class ReportOneBean{

	private String name;	//申請人名稱
	private String userId;	//申請人ID
	private String organization; //人員組織機構
	private String bizRoleCode;  //崗位ID
	private String bizRoleName;  //崗位名稱
	private String resource;   //業務系統
	private String itRoleCode;  //授權角色id
	private 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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章