前端——>后端:
将含有中文的属性拼接在URL后面的时候,传到后端乱码:
前端使用encodeURI(encodeURI(str))对str编码;
后端使用URLDecoder.decode(str,"UTF-8")对str解码;
后端——>前端
业务场景:有两个controller:c1,c2,c1有一些带有中文值的属性,将这些属性以键值对的形式放入RedirectAttributes对象中,redirectAttributes.addAttribute(K,V);c2中直接声明个属性,接受K值。
然后在C2中对带有中文值的属性编码,
redirectAttributes.addAttribute("K", URLEncoder.encode(V,"utf-8"));