<bean id="jasperReportsViewResolver" class="org.springframework.web.servlet.view.jasperreports.JasperReportsViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.jasperreports.JasperReportsMultiFormatView"></property>
<property name="prefix" value="/WEB-INF/jasper/"></property>
<property name="suffix" value=".jrxml"></property>
<property name="contentType" value="text/html"></property>
<property name="jdbcDataSource" ref="druidDataSource"></property>
<property name="reportDataKey" value="jrDatasource"></property>
<property name="order" value="2"></property>
</bean>
@RequestMapping(value = "report/jdbc2", method = RequestMethod.GET)
public String jdbcReport2(
@RequestParam(value = "syudylsh", required = true) String syudylsh,
Model model
) throws JRException, SQLException, IOException, ClassNotFoundException {
model.addAttribute("empNo",7369);
model.addAttribute("format","pdf");
model.addAttribute("jrDatasource", new JREmptyDataSource());
return "jdbc-report";
}
The Normal Result Show Like this
@Test
public void testPrintPdf() throws JRException, InstantiationException, IllegalAccessException {
DBTools.initDataSource("datasources/oracle-scott.properties",DruidDataSource.class);
Connection connection = DBTools.getConnection();
Map<String, Object> params = new HashMap<String, Object>();
params.put("empNo", 7369);
InputStream resourceAsStream = DBTools.class.getClassLoader().getResourceAsStream("jasperreport/demo/jdbc-report.jasper");
JasperReport jasperReport = (JasperReport) JRLoader.loadObject(resourceAsStream);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, connection);
JRPdfExporter exporter = new JRPdfExporter();
exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput("d:/ireport_out/jdbc-report.pdf"));
exporter.exportReport();
}
答案 0 :(得分:0)
现在问题已经解决了。
我已经改变了
model.addAttribute("jrDatasource", new JREmptyDataSource());
到
//datasource is db source
model.addAttribute("jrDatasource", datasource);