我希望JasperReport
使用Spring MVC
,但我使用InternalResourceViewResolver
作为处理方法。当我调用我的报告方法时,它会开始搜索pdfReport.jsp
页面并向我显示404 not found
。但我需要打开报告文件,而不是.jsp
页面!
我的控制器方法:
@RequestMapping(method = RequestMethod.GET, value = "/report/{id}")
public ModelAndView generatePdfReport(ModelAndView modelAndView) {
LOG.debug("--------------generate PDF report----------");
Map<String, Object> parameterMap = new HashMap<String, Object>();
java.util.List<Node> nodeList = nodeService.list();
JRDataSource JRdataSource = new JRBeanCollectionDataSource(nodeList);
parameterMap.put("datasource", JRdataSource);
// pdfReport bean has ben declared in the spring configuration
return new ModelAndView("pdfReport", parameterMap);
}
我的spring xml文件配置:
<mvc:annotation-driven/>
<tx:annotation-driven/>
<context:component-scan base-package="com.datum.fnd">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="contentType" value="text/html; charset=UTF-8" />
<property name="prefix" value="/WEB-INF/pages/"/>
<property name="suffix" value=".jsp"/>
</bean>
<!-- Report pages beans -->
<bean id="pdfReport"
class="org.springframework.web.servlet.view.jasperreports.JasperReportsPdfView"
p:url="classpath:reportTest.jrxml"
p:reportDataKey="datasource" />
答案 0 :(得分:0)
我已经通过一些改变解决了我的问题:
1)将以下代码添加到spring xml配置文件中:
<!-- Jasper report -->
<import resource="jasper-views.xml"/>
<bean class="org.springframework.web.servlet.view.XmlViewResolver">
<property name="location" value="/WEB-INF/spring/jasper-views.xml"/>
<property name="order" value="0"/>
</bean>
2)创建新的jasper-views.xml文件,将以下代码复制并粘贴到其中:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.0.xsd">
<!--here all the url value should contains the valid path for the jrxml file-->
<bean id="pdfReport"
class="org.springframework.web.servlet.view.jasperreports.JasperReportsPdfView"
p:url="classpath:reportTest.jrxml"
p:reportDataKey="datasource" />
</beans>