SpringBoot取出信息


1.打印头信息

@RequestMapping(value = "/upload", method = RequestMethod.POST)
@ResponseBody
public List<UploadResult> upload(@RequestParam(name = "files", required = true) MultipartFile[] multipartFiles,
        @RequestHeader HttpHeaders httpHeaders,
        @RequestHeader(name = "content-range", required = false) String contentRange,
        @RequestHeader(name = "content-disposition", required = false) String contentDisposition,
        @RequestHeader(name = "Block-Index", required = false) Integer blockIndex,
        @RequestHeader(name = "Block-Total", required = false) Integer blockTotal,
        @RequestHeader(name = "Block-Done", required = false) String blockDone

)


System.out.println("-----------------------------------------------------------");
Iterator<String> headerNames = httpHeaders.keySet().iterator();
while (headerNames.hasNext()) {
    String key = headerNames.next();
    List<String> valueList = httpHeaders.getValuesAsList(key);
    String valueStr = "";
    for (String value : valueList) {
        valueStr += "|" + value;
    }
    System.out.println(key + "  -->  " + valueStr);
}


System.out.println("-----------------------------------------------------------");
Enumeration<String> headerNames = request.getHeaderNames();
while (headerNames.hasMoreElements()) {
    String key = headerNames.nextElement();
    String value = request.getHeader(key);
    System.out.println(key + "  -->  " + value);
}




2.打印form参数


Map<String, String[]> parameterMap = request.getParameterMap();
Iterator<Entry<String, String[]>> iterator = parameterMap.entrySet().iterator();
System.out.println("--form--------------------------");
while (iterator.hasNext()) {
    Entry<String, String[]> keyValues = iterator.next();
    String key = keyValues.getKey();
    String[] values = keyValues.getValue();
    System.out.println("--form--------------------------" + key + "  -->  ");
}




3.打印上传文件

System.out.println("-------------------getParts---------------");
Collection<Part> parts = multipartRequest.getParts();
for(Part part: parts) {
    String name = part.getName();
    String contentType = part.getContentType();
    if(contentType == null) {
        InputStream  inputStream  = part.getInputStream();
        int length = inputStream.available();
        byte[] bytes = new byte[length];
        int len = inputStream.read(bytes);                
        String value = new String(bytes, "utf-8");
        System.out.println(name + "  --> " + contentType   + "  --> " + len  + "  --> " + value );
    }
    
}
System.out.println("-------------------getParts---------------");
posted @ 2018-12-31 22:41  ParamousGIS  阅读(203)  评论(0编辑  收藏  举报