我的问题是我无法在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);
}
}
答案 0 :(得分:0)
尝试以下
Resource resource = new ClassPathResource("img/cards/" + faces[j] + "_of_" + suite[i] + ".png");