类 MarshallingView
- 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.xml.MarshallingView
- 所有已实现的接口:
Aware
,BeanNameAware
,ApplicationContextAware
,ServletContextAware
,View
public class MarshallingView extends AbstractView
Spring-MVCView
that allows for response context to be rendered as the result of marshalling by aMarshaller
.The Object to be marshalled is supplied as a parameter in the model and then detected during response rendering. Users can either specify a specific entry in the model via the
sourceKey
property or have Spring locate the Source object.- 从以下版本开始:
- 3.0
- 作者:
- Arjen Poutsma, Juergen Hoeller
字段概要
字段 修饰符和类型 字段 说明 static String
DEFAULT_CONTENT_TYPE
Default content type.从类继承的字段 org.springframework.context.support.ApplicationObjectSupport
logger
从接口继承的字段 org.springframework.web.servlet.View
PATH_VARIABLES, RESPONSE_STATUS_ATTRIBUTE, SELECTED_CONTENT_TYPE
构造器概要
构造器 构造器 说明 MarshallingView()
Construct a newMarshallingView
with noMarshaller
set.MarshallingView(Marshaller marshaller)
Constructs a newMarshallingView
with the givenMarshaller
set.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 protected void
initApplicationContext()
Subclasses can override this for custom initialization behavior.protected boolean
isEligibleForMarshalling(String modelKey, Object value)
Check whether the given value from the current view's model is eligible for marshalling through the configuredMarshaller
.protected Object
locateToBeMarshalled(Map<String,Object> model)
Locate the object to be marshalled.protected void
renderMergedOutputModel(Map<String,Object> model, HttpServletRequest request, HttpServletResponse response)
Subclasses must implement this method to actually render the view.void
setMarshaller(Marshaller marshaller)
Set theMarshaller
to be used by this view.void
setModelKey(String modelKey)
Set the name of the model key that represents the object to be marshalled.从类继承的方法 org.springframework.web.servlet.view.AbstractView
addStaticAttribute, createMergedOutputModel, createRequestContext, createTemporaryOutputStream, exposeModelAsRequestAttributes, generatesDownloadContent, getAttributesMap, getBeanName, getContentType, getRequestContextAttribute, getRequestToExpose, getStaticAttributes, isExposePathVariables, prepareResponse, render, setAttributes, setAttributesCSV, setAttributesMap, setBeanName, setContentType, setExposeContextBeansAsAttributes, setExposedContextBeanNames, setExposePathVariables, setRequestContextAttribute, setResponseContentType, toString, writeToResponse
从类继承的方法 org.springframework.web.context.support.WebApplicationObjectSupport
getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContext
从类继承的方法 org.springframework.context.support.ApplicationObjectSupport
getApplicationContext, getMessageSourceAccessor, requiredContextClass, setApplicationContext
字段详细资料
DEFAULT_CONTENT_TYPE
public static final String DEFAULT_CONTENT_TYPE
Default content type. Overridable as bean property.- 另请参阅:
- 常量字段值
构造器详细资料
MarshallingView
public MarshallingView()
Construct a newMarshallingView
with noMarshaller
set. The marshaller must be set after construction by invokingsetMarshaller(org.springframework.oxm.Marshaller)
.
MarshallingView
public MarshallingView(Marshaller marshaller)
Constructs a newMarshallingView
with the givenMarshaller
set.
方法详细资料
setMarshaller
public void setMarshaller(Marshaller marshaller)
Set theMarshaller
to be used by this view.
setModelKey
public void setModelKey(String modelKey)
Set the name of the model key that represents the object to be marshalled. If not specified, the model map will be searched for a supported value type.
initApplicationContext
protected void initApplicationContext()
从类复制的说明:ApplicationObjectSupport
Subclasses can override this for custom initialization behavior.The default implementation is empty. Called by
ApplicationObjectSupport.initApplicationContext(org.springframework.context.ApplicationContext)
.
renderMergedOutputModel
protected void renderMergedOutputModel(Map<String,Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception
从类复制的说明:AbstractView
Subclasses must implement this method to actually render the view.The first step will be preparing the request: In the JSP case, this would mean setting model objects as request attributes. The second step will be the actual rendering of the view, for example including the JSP via a RequestDispatcher.
- 指定者:
renderMergedOutputModel
在类中AbstractView
- 参数:
model
- combined output Map (nevernull
), with dynamic values taking precedence over static attributesrequest
- current HTTP requestresponse
- current HTTP response- 抛出:
Exception
- if rendering failed
locateToBeMarshalled
protected Object locateToBeMarshalled(Map<String,Object> model) throws IllegalStateException
Locate the object to be marshalled.The default implementation first attempts to look under the configured model key, if any, before attempting to locate an object of supported type.
- 参数:
model
- the model Map- 返回:
- the Object to be marshalled (or
null
if none found) - 抛出:
IllegalStateException
- if the model object specified by the model key is not supported by the marshaller- 另请参阅:
setModelKey(String)
isEligibleForMarshalling
protected boolean isEligibleForMarshalling(String modelKey, Object value)
Check whether the given value from the current view's model is eligible for marshalling through the configuredMarshaller
.The default implementation calls
Marshaller.supports(Class)
, unwrapping a givenJAXBElement
first if applicable.- 参数:
modelKey
- the value's key in the model (nevernull
)value
- the value to check (nevernull
)- 返回:
- whether the given value is to be considered as eligible
- 另请参阅:
Marshaller.supports(Class)