Jaspersoft使用文档Word文件下载.docx
《Jaspersoft使用文档Word文件下载.docx》由会员分享,可在线阅读,更多相关《Jaspersoft使用文档Word文件下载.docx(11页珍藏版)》请在冰豆网上搜索。
![Jaspersoft使用文档Word文件下载.docx](https://file1.bdocx.com/fileroot1/2022-11/21/f8d41f3a-f4e4-467d-969c-a450884c39b5/f8d41f3a-f4e4-467d-969c-a450884c39b51.gif)
然后根据开始你的标签布局设计模版:
(注意,所有的字体显示,要选择上图那3个属性值,否则会出现乱码)
(默认打印出来是不会显示边框的,选中Rectangle标签,右击—>
PaddingandBroders)
预览成功之后会生成一个.jaspersoft文件,用来java代码解析使用.
Java代码调用jaspersoft
1):
导入jar
<
dependency>
<
groupId>
jasperreports<
/groupId>
artifactId>
/artifactId>
version>
5.6.0<
/version>
classifier>
/classifier>
/dependency>
2):
把要打印的模版存到对应的项目目录下
3):
模版里面没有sql版本事例:
publicvoidprintNewExpress(HttpServletRequestrequest,Stringno,
HttpServletResponseresponse)throwsJRException,InstantiationException,IllegalAccessException,IOException{
Collection<
Object>
storesQualitys=newArrayList<
();
List<
Pick>
pick=pickService.printExpressSingle(no);
for(Pickdetail:
pick){
StringcustomerCode=detail.getCustomerCode();
StringcustomerCompany=detail.getCustomerCompany();
StringcustomerMobile=detail.getCustomerMobile();
StringcustomerAddress=detail.getCustomerAddress();
StringcustomerZipcode=detail.getCustomerZipcode();
StringcustomerLocation=detail.getCustomerLocation();
StringclassPath=Thread.currentThread().getContextClassLoader().getResource("
"
).getPath();
StringtemplatePath="
;
ResourcePatternResolverresolver=newPathMatchingResourcePatternResolver();
Resourcehead=resolver.getResource("
classpath:
/com/iceasy/wms/console/controller/xls/template/printCarrierReport_Fed.jasper"
);
templatePath=head.getFile().getAbsolutePath();
//封装报表参数
HashMap<
String,Object>
params=newHashMap<
//获取报表模板
StringfileURL="
com"
+System.getProperty("
file.separator"
)+"
iceasy"
)+
"
wms"
console"
controller"
+System.getProperty("
xls"
)
+"
template"
StringtemplatePathImages=classPath+fileURL+"
checkbox_cheked.png"
params.put("
image_url"
templatePathImages);
//编译成JasperPrint对象
byte[]bytes=JasperRunManager.runReportToPdf(templatePath,params,newJRBeanCollectionDataSource(storesQualitys));
response.setContentType("
application/pdf"
response.setContentLength(bytes.length);
ServletOutputStreamout;
try{
out=response.getOutputStream();
out.write(bytes,0,bytes.length);
out.flush();
out.close();
}catch(IOExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}
}
}
模版里面有sql版本事例:
publicvoidprintPickingList(HttpServletRequestrequest,Stringno,
HttpServletResponseresponse)throwsJRException,InstantiationException,IllegalAccessException,SQLException,IOException{
//获取报表模板
ResourcePatternResolverresolver=newPathMatchingResourcePatternResolver();
/com/iceasy/wms/console/controller/xls/template/printPickingList.jasper"
Resourcebody=resolver.getResource("
/com/iceasy/wms/console/controller/xls/template/printPickingDetailList.jasper"
SqlSessionsqlSession=sqlSessionFactory.openSession();
Connectionconnection=sqlSession.getConnection();
try{
StringtemplatePath=head.getFile().getAbsolutePath();
StringtemplatePath_Index=body.getFile().getAbsolutePath();
pickListJasper"
templatePath_Index);
no"
no);
byte[]bytes=JasperRunManager.runReportToPdf(templatePath,params,connection);
response.setContentType("
response.setContentLength(bytes.length);
ServletOutputStreamout;
out=response.getOutputStream();
out.write(bytes,0,bytes.length);
out.flush();
out.close();
}finally{
sqlSession.close();
}
(注:
有些标签要使用特定的字体,服务器上面可能没有,可以把对应的字体打成jar包上传到私服)