Spring中解析字符串的转换器默认编码居然是ISO-8859-1,如何处理utf-8中文字符
下面这都两个可以
方法一,使用(produces = “application/json; charset=utf-8”):
1 2 3
| @RequestMapping(value="/getUsersByPage",produces = "application/json; charset=utf-8") @ResponseBody public String getUsersByPage(String page,String rows,String text,HttpServletRequest request,HttpServletResponse response){
|
方法二,在spring-mvc.xml中添加:
1 2 3 4 5 6 7 8 9 10 11 12
| <mvc:annotation-driven> <mvc:message-converters> <bean class="org.springframework.http.converter.StringHttpMessageConverter"> <property name="supportedMediaTypes"> <list> <value>application/json;charset=UTF-8</value> </list> </property> </bean> </mvc:message-converters> </mvc:annotation-driven>
|
以上两种方式经过验证都没有问题。