原创

HttpServletRequest接收的是Json格式数据的解决办法


 

 
 @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
throws Exception {
if (handler.getClass().isAssignableFrom(HandlerMethod.class)) {
Authentication Authentication = ((HandlerMethod) handler)
.getMethodAnnotation(Authentication.class);
//如果没用Authentication这个注解标注的接口或者validate=false则直接通过
if (Authentication == null
|| Authentication.validate() == false) {
return true;
} else {
BufferedReader streamReader = new BufferedReader( new InputStreamReader(request.getInputStream(), "UTF-8")); 
            StringBuilder responseStrBuilder = new StringBuilder(); 
            String inputStr; 
            while ((inputStr = streamReader.readLine()) != null) 
        responseStrBuilder.append(inputStr); 
            Map<String ,String> map = JSON.parseObject(Base64.decode(responseStrBuilder.toString()),Map.class);
String userToken = map.get("token");
log.debug("current token**************: " + userToken);
if (StringUtils.isBlank(userToken)) {
returnValue(response);
return false;
} else {
TokenTools tokenTools = new TokenTools();
if (!tokenTools.checkLoginInfo(userToken)) {
returnValue(response);
return false;
}
log.debug("You have logged in successfully!");
return true;
}
}
}else {
return true;
}
}


正文到此结束
该篇文章的评论功能已被站长关闭
本文目录