Spring 无法在webapp/resources/images文件夹中上载图像
我无法上传此代码的图像,虽然它没有显示任何错误,但同时图像也没有保存在文件夹中Spring 无法在webapp/resources/images文件夹中上载图像,spring,spring-mvc,Spring,Spring Mvc,我无法上传此代码的图像,虽然它没有显示任何错误,但同时图像也没有保存在文件夹中 MultipartFile productImage = product.getProductImage(); String rootDirectory = request.getSession().getServletContext().getRealPath("/"); path = Paths.get(rootDirectory + "resources/images/"
MultipartFile productImage = product.getProductImage();
String rootDirectory = request.getSession().getServletContext().getRealPath("/");
path = Paths.get(rootDirectory + "resources/images/" + product.getProductId() + ".png");
if(productImage != null && !productImage.isEmpty()){
try {
productImage.transferTo(new File(path.toString()));
System.out.println("image edited then saved ");
} catch (Exception ex){
ex.printStackTrace();
throw new RuntimeException("Product image saving failed", ex);
}
}
对于这种解决方案,目的是可以的,但尝试其他解决方案。另外,一旦服务器重新启动,路径不可写或者不应写,您将丢失这些映像。