后台接受post请求参数乱码问题

只需在后台获得request后,设置request.setCharacterEncoding("UTF-8");,即可解决乱码问题

1
2
3
4
5
6
public static HttpServletRequest getRequest() throws UnsupportedEncodingException {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
.getRequest();
request.setCharacterEncoding("UTF-8");
return request;
}