这是我的代码,我有 3 个文本字段和 1 个组合框。我使用了 mysql 数据库和休眠我可以创建一个碧玉报告(/home/webwerks/gitpro/Swing/src/report5.jrxml")给这样的路径它没关系,但是我已经设置了outfile的动态路径(jasper report)。你可以看到jButton5ActionPerformed代码,我可以在这个地方给出这样的outfile的静态路径(JasperExportManager.exportReportToPdfFile(jasperPrint,“/home/webwerks/report.pdf”)我可以给出动态路径如何请帮助我
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
if (evt.getSource() == jButton1) {
String s = jTextField1.getText();
String s1 = jTextField2.getText();
String s2 = jTextField3.getText();
String s4 = (String) jComboBox1.getSelectedItem();
Session session = HibernateUtil.getSessionFactory().openSession();
session.beginTransaction();
Performance performance = new Performance();
performance.setFirerating(s4);
performance.setSoundrating(s);
performance.setWidth(s1);
performance.setMaxheight(s2);
session.save(performance);
session.flush();
}
}
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if (evt.getSource() == jButton5) {
try {
Session session = HibernateUtil.getSessionFactory().openSession();
List l = ((org.hibernate.classic.Session) session).find("from Hibernate.Performance");
Map parameters = new HashMap();
InputStream input = new FileInputStream("/home/webwerks/gitpro/Swing/src/report5.jrxml");
JasperDesign jasperDesign = JRXmlLoader.load(input);
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(l);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, ds);
JasperExportManager.exportReportToPdfFile(jasperPrint, "/home/webwerks/report.pdf");
} catch (Exception e) {
}
}
}