解决方法一:@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>

以上两种方式经过验证都没有问题。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-09
  • 2021-10-19
  • 2022-12-23
  • 2022-12-23
  • 2022-01-28
猜你喜欢
  • 2022-12-23
  • 2021-11-28
  • 2021-10-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-08
相关资源
相似解决方案