解决SpringMVC中文乱码问题 -----这是服务器返回参数到前端中文乱码

时间:2023-02-10 11:54:56

方法一,使用(produces = "application/json; charset=utf-8"):

    @RequestMapping(value="/getUsersByPage",produces = "application/json; charset=utf-8")
//    @RequestMapping("/getUsersByPage")
    @ResponseBody
    public String getUsersByPage(String page,String rows,String text,HttpServletRequest request,HttpServletResponse response){

方法二,在spring-mvc.xml中添加:

<!--让所有的Controller能够解析,不可缺少,<mvc:annotation-driven>里面那一整段,用来解决@ResponseBody传输字符串中文乱码问题-->
<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>

解决SpringMVC中文乱码问题 -----这是服务器返回参数到前端中文乱码