Transferred from: http://www.cnblogs.com/ms-grf/p/6756243.html
Report JS
$scope. Printcptempletmasterdetail = function (cpId) { var parameters = { Reportfilename: "reports/ Doctorstation/cptempletmasterdetail.jasper ", parameters: { ' cpId ': CpId } }; var printinfoobject = { type: ' Report ', appletparameters: { is_direct_print:true, is_display:false , Printer_name:null, report_url: "Api/jasper-prints/doctor-station/cp-order-detail" }, Reportparameter:parameters }; Hrutils.postmessagetobaseframe (Printinfoobject, "*"); };
Report Doctorstationprintresource.java
Package Com.heren.his.report.api;import Com.heren.his.report.facade.doctorstationprintfacade;import Com.heren.his.report.vo.jasperprintparamsvo;import Net.sf.jasperreports.engine.jasperprint;import javax.ws.rs.*; Import Javax.ws.rs.core.MediaType; @Path ("Doctor-station") public class Doctorstationprintresource { @ Javax.inject.Inject private Doctorstationprintfacade doctorstationprintfacade; /** * Print path details * @param parameters * @return */ @GET @Path ("Cp-order-detail") @Produces ( {Mediatype.application_octet_stream}) Public Jasperprint Fillcptempletmasterdetailreport (@QueryParam ("parameter") JASPERPRINTPARAMSVO parameters) { return Doctorstationprintfacade.fillcptempletmasterdetailreport (parameters);} }
Report Doctorstationprintfacade.java
Package Com.heren.his.report.facade;import Com.google.common.base.strings;import Com.heren.his.report.common.hrresultset;import Com.heren.his.report.vo.jasperprintparamsvo;import Com.heren.his.report.vo.doctorstation.eroutpblooddetail;import Com.heren.his.report.vo.doctorstation.eroutpbloodvo;import Com.heren.his.report.vo.doctorstation.medicalrecordinfovo;import Net.sf.jasperreports.engine.jasperprint;import Net.sf.jasperreports.engine.data.jrbeancollectiondatasource;import Net.sf.jasperreports.engine.data.jrmapcollectiondatasource;import Org.slf4j.logger;import Org.slf4j.loggerfactory;import Javax.inject.inject;import Java.util.arraylist;import Java.util.List;import Java.util.map;import static Com.heren.his.report.util.reportutils.obtainjasperreportbyfilename;public class Doctorstationprintfacade extends Basejasperfillfacade {private static final Logger Logger = Loggerfactory.getlogger (do Ctorstationprintfacade.class); @Inject Private Medicalinfodatafacade MEDICALINFODATAFACAde /** * Print Path Advice Details * * @param JASPERPRINTPARAMSVO * @return */public Jasperprint Fillcptempletmasterde Tailreport (Jasperprintparamsvo jasperprintparamsvo) {logger.debug ("populate report [{}]; use parameters when populating: [{}].") ", Jasperprintparamsvo.getreportfilename (), jasperprintparamsvo.getparameters ()); Map ReportParam = Jasperprintparamsvo.getparameters ();//js inside Cpid reportparam.put ("Subreport_dir", "reports/doctors Tation/"); Return Hrfillreportwithconnection (Obtainjasperreportbyfilename (Jasperprintparamsvo.getreportfilename ()), ReportParam); }}
Report
1: Create the main report Master.jrxml
The first new two parameters in Master.jrxml, the name is the red label in the code above
Cpid is the primary key used to write SQL, and Subreport_dir is the address used to connect the subreport
Start writing Master.jrxml SQL statements such as
After writing the SQL click on the read fields, you can put the parameters used in the Master.jrxml in fields.
Perfect Master.jrxml
2: Create subreport Nurse.jrxml
The following stage_id is a parameter that is passed from the parent report to the subreport (because the subreport also needs to write the SQL and need to query the criteria)
Sub-report Creation complete
The main point of the configuration subreport is as follows
Then set the Subreport_dir variable of the connection subreport as follows
Generate the. jasper file as follows
Do the test as follows
Report 2 (pass in a SQL primary key with subreports)