Spring VelocityViewResolver 可以处理多种内容类型吗?
我在 REST Spring MVC 应用程序中使用 Spring 的 ContentNegotiatingViewResolver
以及 VelocityViewResolver
,该应用程序将支持许多不同的响应类型。
我希望 Velocity 能够处理多种内容类型,但它似乎只支持 1 种(默认 text/html 或通过 contentType 属性提供)。在下面的配置示例中,我希望 Velocity 支持 html、csv 和自定义内容类型。
这可以用 1 个 VelocityViewResolver 实现吗?或者我是否需要为每种内容类型配置一个?
<bean id="viewResolver" class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<property name="mediaTypes">
<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>
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="mediaTypes">
<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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论