第一種方法:
<!--配置注解驅動-->
<mvc:annotation-driven>
<!--消息轉換器,解決ResponseBody響應中文亂碼-->
<mvc:message-converters>
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes" value="text/html;charset=UTF-8"/>
<property name="defaultCharset" value="UTF-8"/>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
在spring-mvc中的配置文件中配置一個字符串消息轉換器即可。
第二種方法:
@RequestMapping(value = "/login",method = RequestMethod.POST, produces = "application/json;charset=utf-8")