关闭

spring mvc + JasperReports

688人阅读 评论(0) 收藏 举报
分类:

spring mvc 配置

maven 包

<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>5.6.0</version>
</dependency>

 groovy-all.jar 包commons-collections-2.1.jar    commons-beanutils-1.7.ja   commons-digester-1.7.jar  poi-3.2-FINAL-20081019.ja

1、配置显示视图

<!-- 自定义多视图解析器,根据请求后缀调用相应的视图解析器 -->
<bean id="multipleViewResolver" class="com.kayak.kkweb.view.MultipleViewResolver"
p:order="0">
<property name="resolvers">
<map>
<entry key="jrxml">
<!-- Jasper Report 视图 -->
<bean id="jasperReportsViewResolver"
class="org.springframework.web.servlet.view.jasperreports.JasperReportsViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.jasperreports.JasperReportsMultiFormatView" />
<property name="prefix" value="/WEB-INF/jrxml/" />
<property name="contentType" value="text/html;charset=UTF-8" />
<property name="suffix" value="" />
<property name="viewNames" value="cvas_report*" />
<property name="cache" value="true" />
<property name="jdbcDataSource" ref="dataSource" />
<property name="exporterParameters">
<map>
<!-- Force bei allen UTF-8 -->
<entry
key="net.sf.jasperreports.engine.export.JRHtmlExporterParameter.IMAGES_URI">
<value>"../servlets/image?image=12123</value>
</entry>
<entry
key="net.sf.jasperreports.engine.export.JRHtmlExporterParameter.CHARACTER_ENCODING">
<value>UTF-8</value>
</entry>
<entry
key="net.sf.jasperreports.engine.export.JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET">
<bean id="java.lang.Boolean.FALSE"
class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean" />
</entry>
<entry
key="net.sf.jasperreports.engine.export.JRXlsExporterParameter.IS_DETECT_CELL_TYPE">
<bean id="java.lang.Boolean.TRUE"
class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean" />
</entry>
<entry
key="net.sf.jasperreports.engine.export.JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND">
<bean id="java.lang.Boolean.FALSE"
class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean" />
</entry>
<entry
key="net.sf.jasperreports.engine.export.JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS">
<bean id="java.lang.Boolean.TRUE"
class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean" />
</entry>
<entry
key="net.sf.jasperreports.engine.export.JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_COLUMNS">
<bean id="java.lang.Boolean.TRUE"
class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean" />
</entry>
</map>
</property>
</bean>
</entry>
</map>
</property>
</bean>

2、实现类

<property name="viewClass"
value="org.springframework.web.servlet.view.jasperreports.JasperReportsMultiFormatView" />


3 、action 

@RequestMapping(value = "/report")
public String gotoReport(String j, HttpServletRequest request,
HttpServletResponse response, ModelMap modelMap) {
Map<String, Object> params = RequestSupport.getParameters();
String format = (String) params.get("report_format");
String suffix = "";
if (Tools.strIsEmpty(format)) {
format = "html";
suffix = "." + format;
}
String reportExportName = (String) params.get("report_export_name");
if (StringUtils.isBlank(reportExportName)) {
reportExportName = "default";
}
reportExportName = reportExportName + suffix;
modelMap.put("format", format);
modelMap.put("reportExportName", reportExportName);
modelMap.putAll(params);
return j + ".jrxml";
}


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:71758次
    • 积分:1775
    • 等级:
    • 排名:千里之外
    • 原创:100篇
    • 转载:84篇
    • 译文:0篇
    • 评论:3条
    最新评论