Spring MVC 3.x 版本使用 @ResponseBody 返回乱码
2024-10-12 12:26:23
由于万恶的Spring MVC 默认返回编码 是 ISO-8859-1, 使用如下配置, 可以将编码专为UTF-8,
<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>
但是, 如果使用 POST 请求的时候 后台可能会报
org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
因为请求的头信息中 可能请求返回的不是 text/plain;charset=UTF8 这种格式,需要吧request 的 Accept 设置为 text/plain;charset=UTF8.
最新文章
- WCF 框架运行时类图
- oracle表连接——处理连接过程中另外一张表没有相关数据不显示问题
- mac点滴
- CI邮箱中SMTP的一些端口
- android之location 根据接口获取经纬度信息
- PHP入门基础(一)——标记风格、注释、表单获取、字符串类型、变量解析
- linux下手动安装apache详解
- Kill命令模拟1
- SQL学习之汇总数据之聚集函数
- Linux驱动技术(四) _异步通知技术
- html5中的meta标签
- Mac: Android studio+VirtualBox+Genymotion
- Oracle忘记密码如何重
- Java中的String,StringBuilder,StringBuffer三者的区别
- 今天终于想明白为什么java包要倒着写
- P5238 整数校验器
- ROW_NUMBER() OVER(PARTITION BY COLUMN ORDER BY COLUMN)
- Python *Mix_w7
- Jboss7或者wildfly部署war包的问题
- 判断用户访问方式为pc or Phone