Can Spring VelocityViewResolver handle multiple content types?
I'm using Spring's ContentNegotiatingViewResolver
along with VelocityViewResolver
in a REST Spring MVC application which will support many different response types.
I would like Velocity to be able to handle multiple content types, but it seems like it only supports 1 (default text/html or supplied via the contentType property). In the config example below, I would like Velocity to support the html, csv, and custom content types.
Is this possible with 1 VelocityViewResolver? or do I need to configure one for each content type?
<bean id="viewResolver" class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<property name="med开发者_C百科iaTypes">
<map>
<entry key="xml" value="application/xml"/> <!-- MarshallingView -->
<entry key="json" value="application/json"/> <!-- MappingJacksonJsonView -->
<!-- Would like the 3 content types below handled by Velocity -->
<entry key="html" value="text/html"/>
<entry key="csv" value="application/csv"/>
<entry key="custom" value="application/custom"/>
</map>
</property>
<property name="viewResolvers">
<list>
<bean class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
<property name="cache" value="false"/>
<property name="prefix" value=""/>
<property name="suffix" value=".vm"/>
</bean>
</list>
</property>
</bean>
精彩评论