首先是你要下载关于iRport的lib文件,这可以在你下载的jasperReport中全部找到,因为什么版本编译的模板文件之中用对应的版本进行解析,所以要保持你工程中与模板设计的一致性!
首先在web.xml声明关于模板访问的路径例如:
<servlet>
<servlet-name>repdpt</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>4</load-on-startup>
</servlet>
以及他的映射Path:
<!-- 报表文件请求映射定义 -->
<servlet-mapping>
<servlet-name>repdpt</servlet-name>
<url-pattern>*.rep</url-pattern>
</servlet-mapping>
接下来按照SpringMVC的一般规则,需要在WEB-INF的文件夹下面家里一个repdpt-servlet.xml文件,内容如下:
<?xml version="1.0" encoding="GB2312"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<!-- 视图引擎解析器 -->
<bean id="repViewResolver"
class="org.springframework.web.servlet.view.XmlViewResolver">
<property name="location">
<value>/WEB-INF/jsper-views.xml</value>
</property>
</bean>
<!-- Handle clazz -->
<bean id="simDailyReportControllerHandle"
class="com.ecpay.mvc.ftlview.report.Handle.SimDailyReportControllerHandle">
<property name="dataSource" ref="dataSource"></property>
</bean>
<!-- Url -->
<bean id="simDailyReportController"
class="com.ecpay.mvc.ftlview.report.SimDailyReportController">
<property name="viewPath" value="jasperReportsHtmlView"></property>
<property name="handle" ref="simDailyReportControllerHandle"></property>
</bean>
<!-- url mapping -->
<bean id="jasperurlMapping"
class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/report/simdailyreport.rep">
simDailyReportController
</prop>
</props>
</property>
</bean>
</beans>
关于视图解析引擎的文件的配置:
<?xml version="1.0" encoding="GB2312"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<!-- Xls Report 解析 -->
<bean id="jasperReportsXlsView"
class="org.springframework.web.servlet.view.jasperreports.JasperReportsXlsView">
<property name="url"
value="/WEB-INF/jasper/dailyReport_tmp.jasper">
</property>
</bean>
<!-- Html Report 解析 -->
<bean id="jasperReportsHtmlView"
class="com.ecpay.mvc.ftlview.report.JasperReportsGB2312HtmlView">
<property name="url"
value="/WEB-INF/jasper/dailyReport_tmp.jasper">
</property>
</bean>
</beans>
通过上述配置以后,就可以简单的使用SpringMVC实现简单的集成!