我的问题是我无法在 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);
}
}
最佳答案
尝试以下
Resource resource = new ClassPathResource("img/cards/" + faces[j] + "_of_" + suite[i] + ".png");
关于java - Spring mvc项目中如何获取图片文件路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42357188/