spring boot重定向拼接字符乱码
有时候需要用到原生的HTTP Servlet Response或直接返回redirect:http:www....
进行链接的重定向,并且像其中拼接了中文字符就会出现乱码,无论是设置FilterRegistrationBean
还是去配置文件设置都无济于事,寻找许久一直都找不到方法,让人信息,我也如此,幸运的是查看了以前的servlet我找到了解决之法
,如下
String h= "你好呀!";
response.sendRedirect("http:localhost:8080/hello?hello="+ URLEncoder.encode(h,"UTF-8"));
//2
return "redirect:http:localhost:8080/hello?hello="+ URLEncoder.encode(h,"UTF-8")