为什么@requestparam可以在SpringMVC中获取文件上传数据?

时间:2019-03-23 10:01:35

标签: spring spring-boot spring-mvc

@requestparam函数,例如request.getquerystring()。为什么@requestbody无法收到她的multipart / form-data类型的contentType?请告诉我为什么?

    @PostMapping(value = "/uploadFileByUserTrainId", consumes = "multipart/form-data")
    @Student({Student.Authority.A, Student.Authority.B, Student.Authority.C})
    public WebMessage uploadFileByUserTrainId(
            @RequestParam(value = "document", required = false) MultipartFile multipartFile,
            @RequestParam(value = "documetnRe", required = false) MultipartFile multipartFileRe,
            @RequestParam("id") long id,
            @RequestParam(value = "documentFileType", required = false) String fileType,
            @RequestParam(value = "documentFileReType", required = false) String fileReType,
            HttpServletRequest httpServletRequest) {
      // todo
    }

1 个答案:

答案 0 :(得分:1)

@RequestParamMultipart file.一起使用没错

@RequestParam annotation can also be used to associate the part of a "multipart/form-data" request with a method argument supporting the same method argument types. The main difference is that when the method argument is not a String, @RequestParam relies on type conversion via a registered Converter or PropertyEditor