/**
* 获取图片
* @param imgName
* @return
* @throws IOException
*/
public Image getImageByName(String imgName) {
ClassPathResource classPathResource = new ClassPathResource(imgName);
try {
byte[] byteArray = FileCopyUtils.copyToByteArray(classPathResource.getInputStream());
return Image.getInstance(byteArray);
} catch (IOException | BadElementException e1) {
e1.printStackTrace();
}
return null;
}
resources下文件路径 /img/test.png
getImageByName("/img/test.png");
springboot获取静态资源
最新推荐文章于 2023-07-02 18:36:10 发布