@ResponseBody的默认字符集是iso-8859-1, 如何更改为utf8?
下面的配置似乎不起作用。
<bean class = "org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name = "messageConverters">
<list>
<bean class = "org.springframework.http.converter.StringHttpMessageConverter">
<property name = "supportedMediaTypes">
<list>
<value>text/plain;charset=UTF-8</value>
</list>
</property>
</bean>
</list>
</property>
</bean>
答案 0 :(得分:3)
您可以添加produce =“text / plain; charset = UTF-8”来请求映射
@RequestMapping(value = "/rest/create/document", produces = "text/plain;charset=UTF-8")
@ResponseBody
public void create(Document document, HttpServletRespone respone) throws UnsupportedEncodingException {
Document newDocument = DocumentService.create(Document);
return jsonSerializer.serialize(newDocument);
}
答案 1 :(得分:0)
如果您使用的是tomcat,还需要在Tomcat server.xml配置中的URIEncoding="UTF-8"
上指定<Connector>
,如下所述: