我是Spring框架的初学者。
下面的代码我附上了我有一个错误在MultipartFile mf = fileList.get(i);
的错误声明,特别是我可以看到在fileList.get(i)
下的错误说,像标题cannot access org.springframework.core.io.Inputstreamsource
我如何修复它?
public static boolean upload(MultipartHttpServletRequest mtfRequest, int attractionIdx){
List<MultipartFile> fileList = mtfRequest.getFiles("file");
String src = mtfRequest.getParameter("src");
String path = "somepath";
fileList.size();
int size = fileList.size();
for (int i = 0; i < size; i++) {
MultipartFile mf = fileList.get(i);
String originFileName = mf.getOriginalFilename();
long fileSize = mf.getSize();
System.out.println("originFileName : " + originFileName);
System.out.println("fileSize : " + fileSize);
String safeFile = path + attractionIdx + "_" + size + "_" + i + ".png";
try {
mf.transferTo(new File(safeFile));
} catch (IllegalStateException e) {
e.printStackTrace();
return false;
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
return true;
}
2条答案
按热度按时间ioekq8ef1#
必须添加maven依赖项
az31mfrm2#
添加依赖项并将导入更改为如下所示
import org.springframework.core.io.*;