直接取出 post 请求中的 json、得请求体参数、查看 post 请求参数

方法如下:

       try{
            ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
            HttpServletRequest request = requestAttributes.getRequest();

            StringBuffer sb = new StringBuffer() ;
            InputStream is = request.getInputStream();
            InputStreamReader isr = new InputStreamReader(is);
            BufferedReader br = new BufferedReader(isr);
            String s = "" ;
            while((s=br.readLine())!=null){
                sb.append(s) ;
            }
            String result =sb.toString();
            log.info("\n\n ----------- 请求 json 为 :"+result);
        }catch (Exception e){
            ... 
        }

 

你可能感兴趣的:(Java)