SpringMVC @RequesetBody String类型到前台乱码问题

因为 @RequesetBodySting类型的会自动编码为ISO-8859-1格式,前台是UTF-8格式 所以会有乱码问题。

解决方法有很多,比较简单的是在方法前面RequestMapping后面加上produces = "text/html; charset=utf-8" 传到前台的字符串就为UTF-8格式了

@RequestMapping(value = "/upload", produces = "text/html; charset=utf-8")

方法二,后台使用String temp = "../img/" + URLEncoder.encode(newFileName);前台使用var decodeData = decodeURI(returndata); 解码   

原文地址:https://www.cnblogs.com/wgb123/p/7269534.html