SpringBoot之显示本地图片范例
SpringBoot 显示 图片 本地 范例
2023-09-11 14:19:57 时间
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 即可。
相关文章
- JavaWeb-SpringBoot_使用MySQL数据库实现用户管理_demo
- Springboot配置时间格式
- springboot项目不加端口号也可以访问项目的方法
- springboot点击运行没反应,什么都不显示的解决方式
- SpringBoot写后端接口,看这一篇就够了!
- 基于注解SpringAOP,AfterReturning,Before,Around__springboot工程 @Around 简单的使用__SpringBoot:AOP 自定义注解实现日志管理
- SpringBoot升级到2.0后默认时间格式变化_springboot接收date类型参数
- springboot 配置 swagger2
- yml语法学习 SpringBoot配置文件自动装配 yml文件有提示读取配置文件
- 解决springboot+vue+mybatis中,将后台数据分页显示在前台,并且根据页码自动跳转对应页码信息
- springboot之docker启动参数传递
- SpringBoot配置Shiro时@RequiresRoles不起作用
- SpringBoot实例②springboot+jdbcTemplate小例子实现增删查改
- SpringBoot中处理器映射关系注册流程
- 【项目实战】SpringBoot整合Kafka消息队列(基于KafkaTemplate和@KafkaListener实现)
- springboot使用jxls导出excel___(万能通用模板)--- SpringBoot导入、导出Excel文件___SpringBoot整合EasyExcel模板导出Excel