类 JasperReportsMultiFormatView
- java.lang.Object
- org.springframework.context.support.ApplicationObjectSupport
- org.springframework.web.context.support.WebApplicationObjectSupport
- org.springframework.web.servlet.view.AbstractView
- org.springframework.web.servlet.view.AbstractUrlBasedView
- org.springframework.web.servlet.view.jasperreports.AbstractJasperReportsView
- org.springframework.web.servlet.view.jasperreports.JasperReportsMultiFormatView
public class JasperReportsMultiFormatView extends AbstractJasperReportsView
JasperReports view class that allows for the actual rendering format to be specified at runtime using a parameter contained in the model.This view works on the concept of a format key and a mapping key. The format key is used to pass the mapping key from your
Controller
to Spring through as part of the model and the mapping key is used to map a logical format to an actual JasperReports view class.For example, you might add the following code to your
Controller
:Map
Heremodel = new HashMap (); model.put("format", "pdf"); format
is the format key andpdf
is the mapping key. When rendering a report, this class looks for a model parameter under the format key, which by default isformat
. It then uses the value of this parameter to lookup the actualView
class to use.The default mappings for the format lookup are:
csv
-JasperReportsCsvView
html
-JasperReportsHtmlView
pdf
-JasperReportsPdfView
xls
-JasperReportsXlsView
xlsx
-JasperReportsXlsxView
(as of Spring 4.2)
The format key can be changed using the
formatKey
property. The applicable key-to-view-class mappings can be configured using theformatMappings
property.- 从以下版本开始:
- 1.1.5
- 作者:
- Rob Harrop, Juergen Hoeller
- 另请参阅:
setFormatKey(java.lang.String)
,setFormatMappings(java.util.Map<java.lang.String, java.lang.Class<? extends org.springframework.web.servlet.view.jasperreports.AbstractJasperReportsView>>)
字段概要
字段 修饰符和类型 字段 说明 static String
DEFAULT_FORMAT_KEY
Default value used for format key: "format"从类继承的字段 org.springframework.web.servlet.view.jasperreports.AbstractJasperReportsView
CONTENT_DISPOSITION_INLINE, HEADER_CONTENT_DISPOSITION
从类继承的字段 org.springframework.web.servlet.view.AbstractView
DEFAULT_CONTENT_TYPE
从类继承的字段 org.springframework.context.support.ApplicationObjectSupport
logger
从接口继承的字段 org.springframework.web.servlet.View
PATH_VARIABLES, RESPONSE_STATUS_ATTRIBUTE, SELECTED_CONTENT_TYPE
构造器概要
构造器 构造器 说明 JasperReportsMultiFormatView()
Creates a newJasperReportsMultiFormatView
instance with a default set of mappings.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 protected boolean
generatesDownloadContent()
Return whether this view generates download content (typically binary content like PDF or Excel files).Properties
getContentDispositionMappings()
Return the mappings ofContent-Disposition
header values to mapping keys.protected void
renderReport(net.sf.jasperreports.engine.JasperPrint populatedReport, Map<String,Object> model, HttpServletResponse response)
Locates the format key in the model using the configured discriminator key and uses this key to lookup the appropriate view class from the mappings.void
setContentDispositionMappings(Properties mappings)
Set the mappings ofContent-Disposition
header values to mapping keys.void
setFormatKey(String formatKey)
Set the key of the model parameter that holds the format discriminator.void
setFormatMappings(Map<String,Class<? extends AbstractJasperReportsView>> formatMappings)
Set the mappings of format discriminators to view class names.从类继承的方法 org.springframework.web.servlet.view.jasperreports.AbstractJasperReportsView
convertExporterParameters, convertParameterValue, convertReportData, convertToExporterParameter, createReport, exposeLocalizationContext, fillReport, getConvertedExporterParameters, getExporterParameter, getExporterParameters, getJdbcDataSource, getReport, getReportData, getReportDataTypes, initApplicationContext, isUrlRequired, loadReport, loadReport, onInit, postProcessReport, renderMergedOutputModel, setConvertedExporterParameters, setExporterParameters, setHeaders, setJdbcDataSource, setReportDataKey, setSubReportDataKeys, setSubReportUrls
从类继承的方法 org.springframework.web.servlet.view.AbstractUrlBasedView
afterPropertiesSet, checkResource, getUrl, setUrl, toString
从类继承的方法 org.springframework.web.servlet.view.AbstractView
addStaticAttribute, createMergedOutputModel, createRequestContext, createTemporaryOutputStream, exposeModelAsRequestAttributes, getAttributesMap, getBeanName, getContentType, getRequestContextAttribute, getRequestToExpose, getStaticAttributes, isExposePathVariables, prepareResponse, render, setAttributes, setAttributesCSV, setAttributesMap, setBeanName, setContentType, setExposeContextBeansAsAttributes, setExposedContextBeanNames, setExposePathVariables, setRequestContextAttribute, setResponseContentType, writeToResponse
从类继承的方法 org.springframework.web.context.support.WebApplicationObjectSupport
getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContext
从类继承的方法 org.springframework.context.support.ApplicationObjectSupport
getApplicationContext, getMessageSourceAccessor, requiredContextClass, setApplicationContext
字段详细资料
DEFAULT_FORMAT_KEY
public static final String DEFAULT_FORMAT_KEY
Default value used for format key: "format"- 另请参阅:
- 常量字段值
构造器详细资料
JasperReportsMultiFormatView
public JasperReportsMultiFormatView()
Creates a newJasperReportsMultiFormatView
instance with a default set of mappings.
方法详细资料
setFormatKey
public void setFormatKey(String formatKey)
Set the key of the model parameter that holds the format discriminator. Default is "format".
setFormatMappings
public void setFormatMappings(Map<String,Class<? extends AbstractJasperReportsView>> formatMappings)
Set the mappings of format discriminators to view class names. The default mappings are:csv
-JasperReportsCsvView
html
-JasperReportsHtmlView
pdf
-JasperReportsPdfView
xls
-JasperReportsXlsView
xlsx
-JasperReportsXlsxView
(as of Spring 4.2)
setContentDispositionMappings
public void setContentDispositionMappings(Properties mappings)
Set the mappings ofContent-Disposition
header values to mapping keys. If specified, Spring will look at these mappings to determine the value of theContent-Disposition
header for a given format mapping.
getContentDispositionMappings
public Properties getContentDispositionMappings()
Return the mappings ofContent-Disposition
header values to mapping keys. Mainly available for configuration through property paths that specify individual keys.
generatesDownloadContent
protected boolean generatesDownloadContent()
从类复制的说明:AbstractView
Return whether this view generates download content (typically binary content like PDF or Excel files).The default implementation returns
false
. Subclasses are encouraged to returntrue
here if they know that they are generating download content that requires temporary caching on the client side, typically via the response OutputStream.
renderReport
protected void renderReport(net.sf.jasperreports.engine.JasperPrint populatedReport, Map<String,Object> model, HttpServletResponse response) throws Exception
Locates the format key in the model using the configured discriminator key and uses this key to lookup the appropriate view class from the mappings. The rendering of the report is then delegated to an instance of that view class.- 指定者:
renderReport
在类中AbstractJasperReportsView
- 参数:
populatedReport
- the populatedJasperPrint
to rendermodel
- the map containing report parametersresponse
- the HTTP response the report should be rendered to- 抛出:
Exception
- if rendering failed- 另请参阅:
AbstractView.getContentType()
,ServletResponse.setContentType(java.lang.String)
,ServletResponse.setCharacterEncoding(java.lang.String)