解决SPRING MVC 返回JSON串中文乱码有关问题

解决SPRING MVC 返回JSON串中文乱码问题
当在SPRING MVC中使用注解把LIST转换成JSON后返回是乱码的问题,代码如下:



[java] view plaincopy
@RequestMapping(params = "method=getList")    
  public @ResponseBody String getList(ModelMap model){    
     return JSONUtil.list2json(list); //这是一个LIST 转成JSON的工具类    
   } 
 
以上代码为在得到数据后中文变成乱码,解决办法如下 
 
  @RequestMapping(params = "method=getList")    
  public ResponseEntity<String> getList(ModelMap model){    
         HttpHeaders headers = new HttpHeaders();    
         MediaType mediaType=new MediaType("text","html",Charset.forName("GBK"));    
         headers.setContentType(mediaType);    
         ResponseEntity<String> responseEntity =new ResponseEntity<String>(JSONUtil.list2json(list),headers,HttpStatus.OK);    
         return responseEntity;    
  }