在Spring Boot中存储和显示图像

在Spring Boot中存储和显示图像,spring,image,spring-boot,jsp,project-structure,Spring,Image,Spring Boot,Jsp,Project Structure,我正在尝试保存一个徽标(在项目中而不是在DB中)获取并显示在JSP页面上,因为我正在数据库中保存图像的URL,但是当我获取图像时,我没有获取图像。这是我的代码和项目结构的屏幕截图。请在这里帮助我,请让我知道这是否是正确的文件夹,或者我应该将图像保存到其他地方。谢谢 文件保存方法 public static String storeLogoPath(MultipartFile file) { logger.info("File AAYA HAI " + file

我正在尝试保存一个徽标(在项目中而不是在DB中)获取并显示在JSP页面上,因为我正在数据库中保存图像的URL,但是当我获取图像时,我没有获取图像。这是我的代码和项目结构的屏幕截图。请在这里帮助我,请让我知道这是否是正确的文件夹,或者我应该将图像保存到其他地方。谢谢

文件保存方法

public static String storeLogoPath(MultipartFile file) {
        logger.info("File AAYA HAI " + file);
        String path = "";
        try {
            //String paths = "G:/MainWorkSpace/Picture_testing/WebContent/resources/images/"+file.getOriginalFilename();
            path = "G:/MainWorkSpace/TestProjects/ecomProject/src/main/resources/static/img/storeLogo/"+file.getOriginalFilename();
            File newFile = new File(path);
            newFile.createNewFile();
            FileOutputStream myfile = new FileOutputStream(newFile);
            myfile.write(file.getBytes());
            myfile.close();
            logger.info("File should be saved now :: ");
        } catch (Exception e) {
            e.printStackTrace();
        }

        return path;
    }
@RequestMapping(value = "/storeFormshow" ,method = RequestMethod.GET)
    public String addStoreForm(Model theModel) {
        Stores storeObj = new Stores();
        theModel.addAttribute("storeForm",storeObj);
        return "Store/storeForm";
    }
控制器方法

public static String storeLogoPath(MultipartFile file) {
        logger.info("File AAYA HAI " + file);
        String path = "";
        try {
            //String paths = "G:/MainWorkSpace/Picture_testing/WebContent/resources/images/"+file.getOriginalFilename();
            path = "G:/MainWorkSpace/TestProjects/ecomProject/src/main/resources/static/img/storeLogo/"+file.getOriginalFilename();
            File newFile = new File(path);
            newFile.createNewFile();
            FileOutputStream myfile = new FileOutputStream(newFile);
            myfile.write(file.getBytes());
            myfile.close();
            logger.info("File should be saved now :: ");
        } catch (Exception e) {
            e.printStackTrace();
        }

        return path;
    }
@RequestMapping(value = "/storeFormshow" ,method = RequestMethod.GET)
    public String addStoreForm(Model theModel) {
        Stores storeObj = new Stores();
        theModel.addAttribute("storeForm",storeObj);
        return "Store/storeForm";
    }
列表的JSP页面

<%@include file="/WEB-INF/views/Store/StoreTemplet/Header.jsp"%>


<div class="content-wrapper">
                <table class="table" id="table_id">
                    <thead>
                        <tr>
                            <th>Logo</th>
                            <th>ID</th>
                            <th>Store Name</th>
                            <th>Country</th>
                            <th class="text-center">Store Status</th>

                        </tr>
                    </thead>
                    <tbody>

                        <c:forEach var="store" items="${storeList}">
                            <tr>
                            <td> <img src="${store.logoURL}" width="10" height="10"> </td>
                                <td>${store.id}</td>
                                <td><a>${store.storeName}</a></td>
                                <td>${store.country}</td>
                                <td>${store.storeStatus}</td>
                            </tr>
                        </c:forEach>
                    </tbody>
                </table>
</div>

<%@include file="/WEB-INF/views/Store/StoreTemplet/Footer.jsp"%>

将图像添加到resources/static文件夹,然后像下面的img标签一样访问它们

<img src="/images/solr.png" height="50" width="50">

我已经修剪了静态文件夹中的路径,并将其保存在数据库中


这不是正确的方法,但对我来说很有效

我使用文件夹storelogo的原因是我必须存储很多图像实际上我想要的功能是用户可以添加徽标和配置文件图片,两者都应存储在不同的文件夹中,这样在我使用时名称就不会重复和造成混淆Spring MVC结构我用来在web应用程序下保存图像,图像很容易访问,但在Spring boot中,图像不容易访问,对于数据库返回的路径,因此我不能在这里简单地传递图像的特定路径。