@ResponseBody返回String数据,显示中文乱码
失败的尝试:
加上
response.setCharacterEncoding(“UTF-8”);
response.setContentType(“application/json; charset=utf-8”);
完全没用。
解决方法:
加上produces参数即可。
把
@ResponseBody
@RequestMapping("/upload")
public String upload(HttpServletRequest request, HttpServletResponse response) {
//…
}
改成
@ResponseBody
@RequestMapping(value = “/upload”, produces = “application/json; charset=utf-8”)
public String upload(HttpServletRequest request, HttpServletResponse response) {
//…
}