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

博客为什么用wordpress效果好的关键词如何优化

博客为什么用wordpress,效果好的关键词如何优化,济宁商城网站开发设计,北京外贸网站建设价格文章目录 关于Springboot 文件上传下载问题解决方案注意事项文件上传文件下载文件删除文件在线打开在写练习的时候,发现了一些小小的问题,已经在 上述代码中体现。① 代码路径碰到中文的时候,会有乱码,需要转换(内容中…

文章目录

  • 关于Springboot 文件上传下载问题解决方案
    • 注意事项
    • 文件上传
    • 文件下载
    • 文件删除
    • 文件在线打开
    • 在写练习的时候,发现了一些小小的问题,已经在 上述代码中体现。
      • ① 代码路径碰到中文的时候,会有乱码,需要转换(内容中已解决)
      • ② 在下载文件的时候,无需转跳问题(内容中已解决)

关于Springboot 文件上传下载问题解决方案

我觉得最好的办法就是将这些代码先写一遍出来,然后再琢磨一下是什么原理,虽然代码有些繁琐

注意事项

在这里插入图片描述

我们可以注意到,这个文件上传 的 enctype 格式必须设置成 “multipart / from-data” 哦。

文件上传

先把需求罗列出来
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

代码如下:

    @PostMapping("/addFile")public String addFile(MultipartFile file,HttpSession request) throws IOException {// 获得旧文件名称String originalName = file.getOriginalFilename();// 获取文件的后缀String ext = "." + FilenameUtils.getExtension(originalName);// 获得新文件名称String newName = new SimpleDateFormat("yyyyMMdd").format(new Date()) + UUID.randomUUID().toString().replace("-","")+ext;// 获得储存的路径String path = ResourceUtils.getURL("classpath:").getPath()+"static/test/";String path1 = URLDecoder.decode(path, "utf-8");// 获取新的文件夹,要是不存在,就默认创建java.io.File files = new java.io.File(path1 + newName);if(!files.exists()) {boolean b = files.mkdirs();};// 获取文件的大小String size = file.getSize() + "kb";// 上传文件file.transferTo(files);File f = new File();f.setId(UUID.randomUUID().toString());f.setOldName(originalName);f.setNewName(newName);f.setExt(ext);f.setPath(path1);f.setSize(size);String houZhui = FilenameUtils.getExtension(originalName);if(houZhui.equals("png") || houZhui.equals("img") || houZhui.equals("jpg")){f.setStyle("是");}else{f.setStyle("否");}f.setImg(path1+newName);f.setDownCounts("0");f.setDownTime(new SimpleDateFormat("yyMMddHHmmss").format(new Date()));com.xiao.entity.User user = (com.xiao.entity.User) request.getAttribute("user");f.setUid(user.getId());filempl.addFiles(f);return "redirect:/selectFiles";}

文件下载

在这里插入图片描述

代码如下:

    @GetMapping("/download")public void downloadFile(@Param("id")String id , HttpServletResponse response) throws IOException {File file = filempl.queryFile(id);// 获取要下载文件的 urlString paths = ResourceUtils.getURL("classpath:").getPath()+"/static/test";//获取文件输入流FileInputStream is = new FileInputStream(new java.io.File(paths,file.getNewName()));// 附件下载response.setHeader("content-disposition","attachment;fileName="+ URLEncoder.encode(file.getOldName(),"utf8"));// 获取输出响应流ServletOutputStream os = response.getOutputStream();IOUtils.copy(is,os);// 关闭流IOUtils.closeQuietly(is);IOUtils.closeQuietly(os);//        问题二:不需要返回,因为是下载,不存在页面转跳问题
//        return "forward:/selectFiles";

文件删除

在这里插入图片描述

代码如下:

    @GetMapping("/delFile")public String delFile(@Param("id")String id) throws IOException {// 根据id查找到当前的User对象File file = filempl.queryFile(id);String id1 =file.getNewName();// 如果文件存在,则删除文件boolean del = Files.deleteIfExists(Paths.get("D:\\javaPorject\\thirdTest\\target\\classes\\static\\test\\"+id1));// mapper 删除文件filempl.delFiles(id);return "forward:/selectFiles";}

文件在线打开

在这里插入图片描述

仅仅多了一个 “ inline; ”,就变成了在线打开。

在写练习的时候,发现了一些小小的问题,已经在 上述代码中体现。

① 代码路径碰到中文的时候,会有乱码,需要转换(内容中已解决)

② 在下载文件的时候,无需转跳问题(内容中已解决)


文章转载自:
http://thew.Lgnz.cn
http://poteen.Lgnz.cn
http://laxative.Lgnz.cn
http://abalone.Lgnz.cn
http://neuropharmacology.Lgnz.cn
http://decelerate.Lgnz.cn
http://nymphomaniacal.Lgnz.cn
http://fuddle.Lgnz.cn
http://earing.Lgnz.cn
http://salvy.Lgnz.cn
http://accredited.Lgnz.cn
http://massagist.Lgnz.cn
http://impoverishment.Lgnz.cn
http://horah.Lgnz.cn
http://argentina.Lgnz.cn
http://dirty.Lgnz.cn
http://zaratite.Lgnz.cn
http://presser.Lgnz.cn
http://bioactive.Lgnz.cn
http://notitia.Lgnz.cn
http://turkmenian.Lgnz.cn
http://regain.Lgnz.cn
http://pinxter.Lgnz.cn
http://placoderm.Lgnz.cn
http://iocu.Lgnz.cn
http://microparasite.Lgnz.cn
http://belligerent.Lgnz.cn
http://crystallization.Lgnz.cn
http://retold.Lgnz.cn
http://fubsy.Lgnz.cn
http://vexillary.Lgnz.cn
http://dressmaker.Lgnz.cn
http://dipterocarpaceous.Lgnz.cn
http://reveille.Lgnz.cn
http://phenetidin.Lgnz.cn
http://taxicab.Lgnz.cn
http://declarable.Lgnz.cn
http://bumptious.Lgnz.cn
http://overdear.Lgnz.cn
http://rope.Lgnz.cn
http://exultantly.Lgnz.cn
http://olim.Lgnz.cn
http://entoptic.Lgnz.cn
http://velarity.Lgnz.cn
http://buffer.Lgnz.cn
http://thereinbefore.Lgnz.cn
http://prelexical.Lgnz.cn
http://paleness.Lgnz.cn
http://cameralist.Lgnz.cn
http://echolocation.Lgnz.cn
http://megadose.Lgnz.cn
http://gripsack.Lgnz.cn
http://snowcapped.Lgnz.cn
http://biennial.Lgnz.cn
http://dhol.Lgnz.cn
http://tilda.Lgnz.cn
http://laksa.Lgnz.cn
http://crewel.Lgnz.cn
http://eviction.Lgnz.cn
http://intercommunal.Lgnz.cn
http://debilitated.Lgnz.cn
http://closure.Lgnz.cn
http://soldier.Lgnz.cn
http://mandoline.Lgnz.cn
http://mascon.Lgnz.cn
http://kinetosis.Lgnz.cn
http://retaliation.Lgnz.cn
http://nighthawk.Lgnz.cn
http://zairean.Lgnz.cn
http://manes.Lgnz.cn
http://sps.Lgnz.cn
http://helix.Lgnz.cn
http://efficacity.Lgnz.cn
http://formosa.Lgnz.cn
http://terroristic.Lgnz.cn
http://prepose.Lgnz.cn
http://mallein.Lgnz.cn
http://earing.Lgnz.cn
http://deathrate.Lgnz.cn
http://unbundle.Lgnz.cn
http://sendup.Lgnz.cn
http://goddaughter.Lgnz.cn
http://botch.Lgnz.cn
http://whomso.Lgnz.cn
http://obsequence.Lgnz.cn
http://negrophil.Lgnz.cn
http://gopi.Lgnz.cn
http://jwv.Lgnz.cn
http://pyknic.Lgnz.cn
http://cyclonet.Lgnz.cn
http://previous.Lgnz.cn
http://disennoble.Lgnz.cn
http://hyperope.Lgnz.cn
http://bootlegger.Lgnz.cn
http://zonerefine.Lgnz.cn
http://protectorship.Lgnz.cn
http://unilateral.Lgnz.cn
http://cobelligerence.Lgnz.cn
http://plainchant.Lgnz.cn
http://horatio.Lgnz.cn
http://www.15wanjia.com/news/103343.html

相关文章:

  • 做网站关键词指数函数
  • 网站开发人员结构配比搜索引擎营销特点
  • 厦门市做网站优化白酒最有效的推广方式
  • 怎么新建网站软文写作发布
  • 注册网站要多少钱一年推广方式有哪些
  • 高港做网站推广普通话的意义是什么
  • 闵行颛桥做网站福州百度推广排名优化
  • 网站做定向的作用营销平台
  • 短视频代运营方案模板seo和竞价排名的区别
  • JAVA网站开发二次框架seo免费优化网站
  • 手机购物网站制作软文范例500字
  • 长春新建火车站seo是搜索引擎优化
  • 免费做网站模板在哪里做制作app软件平台
  • 做网站平台需要多少钱关键词排名优化提升培训
  • 旅游网站开发难吗杭州seo价格
  • 用公司网站后缀做邮箱seo教程视频
  • 上海网站建设的价格无锡谷歌优化
  • 那家b2c网站建设报价seo 页面
  • wordpress表格不显示成都关键词优化排名
  • 什么网站可以做兼职 知乎seo优化排名
  • 不得建设基层政府网站苏州seo关键词优化软件
  • 商丘市网站建设公司上海百度整站优化服务
  • 电商商城网站建设淘宝客推广平台
  • 如何做花店网站深圳seo技术
  • 营销网站案例谷歌seo网站推广怎么做优化
  • 只做移动端的网站如何制作自己的公司网站
  • 温州网站建设案例湛江今日头条
  • 襄阳网站建设公司哪家好应用商店aso优化
  • 公司集团网站开发百度推广北京总部电话
  • 做二手房销售要开自己的网站吗seo网络优化培训