做 java 前端开发,常常会遇到后台数据编码 UTF8,传递到前端却乱码(前端也使用 utf8 编码解码)。可以尝试下面的步骤去解决。
1.确认 Controller 中的 response 设置响应的数据格式和编码,如 text/html;charset=UTF-8; 或 application/json;charset=UTF-8
2.若以注解方式实现 Controller,则加入注解: RequestMapping(Value="view.html"; produces={"text/html;charset=UTF-8"})
3.若以上两种方法不凑效,只能自己对返回数据进行 URLEncode ,传到前端再进行 URLDecode。