Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在SpringMVC项目中获取图像文件路径?_Java_Spring Mvc - Fatal编程技术网

Java 如何在SpringMVC项目中获取图像文件路径?

Java 如何在SpringMVC项目中获取图像文件路径?,java,spring-mvc,Java,Spring Mvc,我的问题是在spring项目中无法获取从资源文件夹到主包的映像路径。我的代码如下 for (int i = 0; i < SUITE; i++) { for(int j = 0; j < FACE ; j++){ Card card = new Card(); BufferedImage temp = null; Resource resource = new FileSystemResou

我的问题是在spring项目中无法获取从资源文件夹到主包的映像路径。我的代码如下

  for (int i = 0; i < SUITE; i++) {
        for(int j = 0; j < FACE ; j++){

            Card card = new Card();
            BufferedImage temp = null;
            Resource resource = new FileSystemResource("src/main/webapp/resources/img/cards/" + faces[j] + "_of_" + suite[i] + ".png");
            card.setSuite(suite[i]);
            card.setFace(faces[j]);
            card.setValue(values[j]);
            card.setPath(resource.getFilename());

            try {
                temp = ImageIO.read(new File(card.getPath()));
            } catch (IOException e) {
                e.printStackTrace();
            }
            card.setImg(temp);
            deck.add(card);
        }
    }
for(int i=0;i
试试下面的方法

Resource resource = new ClassPathResource("img/cards/" + faces[j] + "_of_" + suite[i] + ".png");
您也可以参考下面的内容

Resource resource = new ClassPathResource("img/cards/" + faces[j] + "_of_" + suite[i] + ".png");
你也可以引用