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

手机网站 自适应wordpress自定义链接后404

手机网站 自适应,wordpress自定义链接后404,hao123上网从这里开始,做网站的怎样能翻页目录 1、上传文件1.1、代码1.2、postman测试截图 2、下载resources目录中的模板文件2.1、项目结构2.2、代码2.3、使用场景 3、预览文件3.1、项目结构3.2、代码3.3、使用场景 1、上传文件 1.1、代码 PostMapping("/uploadFile") public String uploadFile(Multipart…

目录

      • 1、上传文件
        • 1.1、代码
        • 1.2、postman测试截图
      • 2、下载resources目录中的模板文件
        • 2.1、项目结构
        • 2.2、代码
        • 2.3、使用场景
      • 3、预览文件
        • 3.1、项目结构
        • 3.2、代码
        • 3.3、使用场景

1、上传文件

1.1、代码
@PostMapping("/uploadFile")
public String uploadFile(MultipartFile file) {System.out.println("文件名称:" + file.getOriginalFilename());return "成功";
}@PostMapping("/uploadFile2")
public String uploadFile2(@RequestParam("file") MultipartFile file
) {System.out.println("文件名称:" + file.getOriginalFilename());return "成功";
}@PostMapping("/uploadFile3")
public String uploadFile3(@RequestPart("file") MultipartFile file
) {System.out.println("文件名称:" + file.getOriginalFilename());return "成功";
}// 发送文件的同时带上参数
@PostMapping("/uploadFile4")
public String uploadFile4(@RequestPart("file") MultipartFile file, // 可以换成“MultipartFile file”或者“@RequestParam("file") MultipartFile file”@RequestParam("id") String id
) {System.out.println("文件名称:" + file.getOriginalFilename());System.out.println("id:" + id);return "成功";
}
1.2、postman测试截图

在这里插入图片描述

2、下载resources目录中的模板文件

2.1、项目结构

假设resources目录下有一个pdf文件:用户数据导入模板.xlsx,然后我们来下载该文件

在这里插入图片描述

2.2、代码
import org.apache.tomcat.util.http.fileupload.IOUtils;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.http.MediaType;
import org.springframework.http.MediaTypeFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;@RestController
public class TestController {@GetMapping("/downloadLocalFile")public void downloadLocalFile(HttpServletResponse response) throws IOException {String fileName = "用户数据导入模板.xlsx";Resource r = new ClassPathResource(fileName);try (FileInputStream fileInputStream = new FileInputStream(r.getFile());ServletOutputStream outputStream = response.getOutputStream();) {response.setContentType("application/force-download");try {fileName = new String(fileName.getBytes("utf-8"), "ISO-8859-1");} catch (UnsupportedEncodingException e) {e.printStackTrace();}response.setHeader("Content-Disposition", "attachment;filename=" + fileName);IOUtils.copyLarge(fileInputStream, outputStream);} catch (Exception e) {e.printStackTrace();}}
}
2.3、使用场景

在这里插入图片描述

3、预览文件

3.1、项目结构

resources下面的文件为例,展示预览文件的代码,这是从本地获取文件,当然也可以通过其他方式获取文件

在这里插入图片描述

3.2、代码
import org.apache.tomcat.util.http.fileupload.IOUtils;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.http.MediaType;
import org.springframework.http.MediaTypeFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;@RestController
public class TestController {@GetMapping("/previewLocalFile")public void previewLocalFile(HttpServletResponse response) throws IOException {String fileName = "SQL必知必会(第5版).pdf";Resource r = new ClassPathResource(fileName);try (FileInputStream fileInputStream = new FileInputStream(r.getFile());ServletOutputStream outputStream = response.getOutputStream();) {// 区别点1:将“response.setContentType("application/force-download");”替换成下面内容response.setContentType(MediaTypeFactory.getMediaType(fileName).orElse(MediaType.APPLICATION_OCTET_STREAM).toString());try {fileName = new String(fileName.getBytes("utf-8"), "ISO-8859-1");} catch (UnsupportedEncodingException e) {e.printStackTrace();}// 区别点2:预览是“filename”,下载是“attachment;filename=”response.setHeader("Content-Disposition", "filename=" + fileName);IOUtils.copyLarge(fileInputStream, outputStream);} catch (Exception e) {e.printStackTrace();}}
}
3.3、使用场景

在网盘软件中预览pdf文件

http://www.yayakq.cn/news/318130/

相关文章:

  • 建站之星有手机版模板网站建设三方合同范本
  • 雅虎网站优化怎么做凡客设计
  • 重庆城乡建设网站首页wordpress公众号验证码
  • 织梦添加网站名称添加新变量音乐网站设计外国
  • 电子商务网站建设过程怎么做免费网站教程
  • 网站建设、微信小程序、贵州建设公司网站
  • 网站备案简介怎么写网站后台换图片
  • 网站建设 麦肯趋势商标注册证电子版查询
  • 上海市嘉定区建设银行网站免费logo设计 u钙
  • jsp网站开发公司wordpress模板 简单
  • 手机如何做api网站佛山做网站的哪个好
  • 公司主页和公司网站深圳物流公司大全排名
  • 教育网站制作哪个好网站模板下载模板下载
  • 上海网站建设开发公司微信客户端免费下载app
  • 晚上正能量网站大全网站统计代码怎么弄
  • 彩网站开发wordpress文章图片很小
  • 手机百度app下载安装深圳设计优化公司
  • 网站中医建设沈阳做网站客户多吗
  • 双滦区seo整站排名wordpress添加面包屑
  • gofair外贸建站淘宝seo优化
  • 温州网站建设公司排名渭南做网站公司
  • 网上怎么接单做网站北京网站建设著名公司
  • 白银网站建设公司注册公司带科技两个字的条件
  • 网站建设颜色福田南山龙华盐田
  • 电子商务网站建设的开发流程怎么对网站做seo优化
  • 网站建设学的是什么知识企业网站托管外包怎么做
  • 加强文明网站建设网络推广方案下拉管家xiala11
  • o2o网站建设流程慈溪网站建设网站推广
  • 医院网站推广渠道旅游网站设计参考文献
  • 河南省建设厅网站打不开抖音小程序开通