Java-SpringMvc-@ResponseBody返回中文字符串乱码

第一种、注解

    @RequestMapping(value = "/test.do", method = {RequestMethod.GET},produces = "text/plain;charset=utf-8")
    @ResponseBody
    public String test(HttpServletResponse response) {
  }

第二种、spring mvc 配置文件

    
    <mvc:annotation-driven>
        
        <mvc:message-converters>
            <bean class="org.springframework.http.converter.StringHttpMessageConverter">
                <constructor-arg name="defaultCharset" value="UTF-8">constructor-arg>
            bean>
        mvc:message-converters>
    mvc:annotation-driven>

 

转载于:https://www.cnblogs.com/bjlhx/p/6639578.html

你可能感兴趣的:(Java-SpringMvc-@ResponseBody返回中文字符串乱码)