方法一:
在@RequestMapping(value="/ValidMobile",produces = "text/html;charset=UTF-8")中,加上produces = "text/html;charset=UTF-8"。
@RequestMapping(value="/ValidMobile",produces = "text/html;charset=UTF-8")
@ResponseBody
public String validMobile(@RequestBody String param) {
User user = new Gson().fromJson(param, User.class);
ResponseBean rb = new ResponseBean;
rb.setResultMsg("中文乱码");
return new Gson().toJson(rb);
}
方法二(推荐):
在spring-servlet.xml配置文件中加入
<!-- 注解驱动 -->
<mvc:annotation-driven>
<!-- 指定http返回编码格式 -->
<mvc:message-converters>
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html;charset=UTF-8</value>
<value>application/json;charset=UTF-8</value>
<value>*/*;charset=UTF-8</value>
</list>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>