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 即可。

  • 相关阅读:
    11 Jun 18 复习,HTTP
    11 Jun 18 Django
    8 Jun 18 复习,mysql
    8 Jun 18 Bootstrap
    7 Jun 18 复习,文件,函数,sorted,colletions
    7 Jun 18 Bootstrap
    pip 使用方法
    http协议 1.1
    mysql 的视图 触发器 事务 存储过程 内置函数 流程控制 索引
    day 29 守护进程/互斥锁/IPC通信机制/生产者消费者模型
  • 原文地址:https://www.cnblogs.com/gongxr/p/10212593.html
Copyright © 2011-2022 走看看