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
Spring 无法在webapp/resources/images文件夹中上载图像_Spring_Spring Mvc - Fatal编程技术网

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);
    }
}

对于这种解决方案,目的是可以的,但尝试其他解决方案。另外,一旦服务器重新启动,路径不可写或者不应写,您将丢失这些映像。