java spring无法访问列表multipartfile中的org.springframework.core.io.Inputstreamsource

ffscu2ro  于 2023-03-21  发布在  Java
关注(0)|答案(2)|浏览(309)

我是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;
}
ioekq8ef

ioekq8ef1#

必须添加maven依赖项

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
</dependency>
az31mfrm

az31mfrm2#

添加依赖项并将导入更改为如下所示
import org.springframework.core.io.*;

相关问题