zoukankan      html  css  js  c++  java
  • SpringBoot之显示本地图片范例

    controller

        // 扫描指定目录下的图片进行展示
        @RequestMapping("/showPics")
        public ModelAndView showPics(ModelAndView mv) {
            // 图片存放路径
            String picPath = Constant.CONFIG_PROPERTIES.getProperty("download.path");
            // 获取图片
            List<File> picList = MyFileUtils.listFilesBySuffixs(picPath, Constant.PIC_SUFFIXS, true);
            mv.setViewName("showPics");
            mv.addObject("picList", picList);
            return mv;
        }

    配置文件(application.properties)

    # 本地图片
    spring.mvc.static-path-pattern=/image/**
    spring.resources.static-locations=file:C://Temp/pic/

     配置图片目录地址映射。

    视图(showPics.ftl)

    <!DOCTYPE html>
    <html>
    <head>
        <title>显示所有图片</title>
        <meta charset="UTF-8"/>
        <meta name="viewport" content="width=device-width, initial-scale=1"/>
    </head>
    <body>
    <div class="container">
        <div class="row">
            <div class="col-md-4">
                <div class="panel panel-primary">
                    <div class="panel-heading text-center">
                        <span class="panel-title">显示所有图片</span>
                    </div>
    
                    <#list picList as pic>
                    <br>
                    <div class="panel-body">
                        <#--<img src="./image/zz.png" width="400" height="50"/>-->
                        <img src="./image/${pic.name}" width="50%" height="50%"/>
                    </div>
                    </#list>
    
                </div>
            </div>
        </div>
    </div>
    </body>
    </html>

    访问 http://localhost:8080/showPics 即可。

  • 相关阅读:
    遗传算法求解旅行商(TSP)问题 -- python
    office 小技巧
    oracle创建dblink
    c# equals与==的区别
    两人之间的一些参数
    .net 枚举(Enum)使用总结
    SQL Server 日期的加减函数: DATEDIFF DATEADD
    jquery操作select
    AS3帮助手册
    Razor和HtmlHelper的使用意义
  • 原文地址:https://www.cnblogs.com/gongxr/p/10212593.html
Copyright © 2011-2022 走看看