废话不多说直接上代码,主要是后端代码,前端只要在表单里多放几个file标签就好了。
单个文件:
public void upfile(HttpServletRequest httpServletRequest) throws Exception {
MultipartHttpServletRequest multipartHttpServletRequest = (MultipartHttpServletRequest) httpServletRequest;
MultipartFile multipartFile = multipartHttpServletRequest.getFile("file");
// 获取到文件的真实名
System.out.println(multipartFile.getOriginalFilename());
}
多个文件:
public void upfile(HttpServletRequest httpServletRequest)
throws Exception {
MultipartHttpServletRequest multipartHttpServletRequest = (MultipartHttpServletRequest) httpServletRequest;
// 拿到多个文件的list
List<MultipartFile> multipartFiles = multipartHttpServletRequest.getFiles("file");
for (MultipartFile mFile : multipartFiles) {
// 获取到文件的真实名
System.out.println(mFile.getOriginalFilename());
}
}