在spring-mvc.xml配置文件中添加
<bean
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<list>
<bean
class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<bean class="org.springframework.http.MediaType">
<constructor-arg index="0" value="text" />
<constructor-arg index="1" value="plain" />
<constructor-arg index="2" value="UTF-8" />
</bean>
</list>
</property>
</bean>
</list>
</property>
</bean>
注意:上面的配置应该写在controller的扫描配置之前
本文介绍如何在Spring MVC中配置消息转换器,以便支持特定的媒体类型如text/plain及字符集UTF-8,确保控制器能正确处理HTTP请求。
1万+

被折叠的 条评论
为什么被折叠?



