当前位置: 首页 > news >正文

项目知识点总结-住房图片信息添加-Excel导出

(1)住房信息添加

Controller:

@RequestMapping("/add")public String add(Home home, Model model) throws IOException{String sqlPath = null;//定义文件保存的本地路径String localPath="D:\\AnZhuang\\Java项目\\选题\\Xin-XiangMu\\Hotel_Manage-master\\src\\main\\webapp\\upload\\";//定义 文件名String filename=null;if(!home.getFile().isEmpty()){//生成uuid作为文件名称String uuid = UUID.randomUUID().toString().replaceAll("-","");//获得文件类型(可以判断如果不是图片,禁止上传)String contentType=home.getFile().getContentType();//获得文件后缀名String suffixName=contentType.substring(contentType.indexOf("/")+1);//得到 文件名filename=uuid+"."+suffixName;System.out.println(filename+"图片名字");//文件保存路径home.getFile().transferTo(new File(localPath+filename));}//把图片的相对路径保存至数据库sqlPath = "/upload/"+filename;System.out.println(sqlPath);home.setImg(sqlPath);homeService.addHome(home);model.addAttribute("home",home);return ("redirect:/home/list");}

Service 

 

Dao

(2)Excel文件导出

页面跳转: 

导出

Controller:

 @RequestMapping("/home")public void excel_home(HttpServletResponse response )throws IOException {response.setCharacterEncoding("UTF-8");List<Home> homeList=homeService.queryAllHome();//创建excel文件HSSFWorkbook wb = new HSSFWorkbook();//创建sheet页HSSFSheet sheet = wb.createSheet("房间信息");//创建标题行HSSFRow titleRow = sheet.createRow(0);titleRow.createCell(0).setCellValue("编号");titleRow.createCell(1).setCellValue("房间号");titleRow.createCell(2).setCellValue("房间类型");titleRow.createCell(3).setCellValue("价格");titleRow.createCell(4).setCellValue("状态");titleRow.createCell(5).setCellValue("描述");for(Home home:homeList){HSSFRow dataRow = sheet.createRow(sheet.getLastRowNum()+1);dataRow.createCell(0).setCellValue(home.getId());dataRow.createCell(1).setCellValue(home.getNum());dataRow.createCell(2).setCellValue(home.getH_Type());dataRow.createCell(3).setCellValue(home.getPrice());dataRow.createCell(4).setCellValue(home.getState());dataRow.createCell(5).setCellValue(home.getText());}// 设置下载时客户端Excel的名称response.setContentType("application/octet-stream;charset=utf-8");response.setHeader("Content-Disposition", "attachment;filename="+ new String("房间信息表".getBytes(),"iso-8859-1") + ".xls");OutputStream ouputStream = response.getOutputStream();wb.write(ouputStream);ouputStream.flush();ouputStream.close();}

Service: 

 

Dao

(3)前端定时器

               !(function run(wait){if(wait <= 0) {location.href = "/jump/index";}else{wait--;setTimeout(function(){document.getElementById("wait").innerHTML = wait;run(wait);},1000);}})(3);

 

http://www.lryc.cn/news/214639.html

相关文章:

  • 第三届iEnglish全国ETP大赛决赛即将启动
  • 创造产业链协同优势后,凌雄科技在DaaS行业转动成长飞轮
  • 【protobuf】protobuf自定义数据格式,CMake编译C++文件读写自定义数据
  • 解决:http://localhost:8080 不在以下 request 合法域名列表中
  • Linux普通用户提权(sudo)
  • 链表指定节点的插入
  • 解决问题Conda:CondaValueError: Malformed version string ‘~’ : invalid character(s)
  • Sci Immunol丨Tim-3 适配器蛋白 Bat3 是耐受性树突状细胞
  • 天软特色因子看板(2023.10 第14期)
  • Photoshop(PS)2021版 安装教程(图文教程超详细)
  • 详解React:Props构建可复用UI的基石
  • 【Unity】【VR开发疑难】Unity运行就报无法启动XR Plugin
  • 本地启动Elasticsearch(docker启动)
  • JVM修炼印记之初识
  • 开关电源老化试验和性能检测系统软件
  • 水库大坝可视化智能远程监管方案,助力安全监测智能巡检
  • C#学习系列之虚方法和多态
  • 面试算法44:二叉树中每层的最大值
  • JWT的头部、载荷和签名分别包含哪些信息?
  • 【烧火柴问题】奇思妙想火柴
  • C++数据结构算法篇Ⅰ
  • Python selenium获取元素信息
  • 测试Winsock的select
  • CentOS 搭建 Hadoop3 高可用集群
  • ModuleNotFoundError: No module named ‘paddle.fluid.incubate.fleet‘
  • 【Java】Java中的引用类型
  • File类、方法递归
  • MySQL - 系统库之 sys
  • GoLong的学习之路(十七)基础工具之Gin框架使用JWT(前后端分离)
  • 【代码数据】2023粤港澳大湾区金融数学建模B题分享