解決方法一:
@RequestMapping(value="/getphone",produces = "text/plain;charset=utf-8")
/**輸入手機號碼后判斷手機號是否存在*/
@RequestMapping(value="/getphone",produces = "text/plain;charset=utf-8")
@ResponseBody
public String getphone(String phone,HttpSession session){
Users u=service.selectPhoneService(phone);
if(u==null){//如果為空,則需要注冊
String str="請您先注冊,再登錄。";
session.setAttribute("str", str);
return "請您先注冊,再登錄。";
}
return "true";
以上方法試過無效
方法二,在spring-mvc.xml中添加:
<!-- 處理請求返回json字符串的中文亂碼問題 -->
<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>
