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

做网站销售好不好链爱交易平台

做网站销售好不好,链爱交易平台,软件开发服务开票税目,怎么做时时彩网站平台目录 1. 新建一个springboot项目2. 配置文件application.propertiesapplication.yml 3. 控制类实现文件上传和下载4. 测试 1. 新建一个springboot项目 新建一个springboot项目&#xff0c;选择web&#xff0c;默认即可. 主要pom配置文件如下&#xff1a; <parent><gr…

目录

  • 1. 新建一个springboot项目
  • 2. 配置文件
    • application.properties
    • application.yml
  • 3. 控制类实现文件上传和下载
  • 4. 测试

1. 新建一个springboot项目

      新建一个springboot项目,选择web,默认即可.

      主要pom配置文件如下:

<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.2.10.RELEASE</version><relativePath/> <!-- lookup parent from repository --></parent><properties><maven.compiler.source>11</maven.compiler.source><maven.compiler.target>11</maven.compiler.target><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties><dependencies><!--web包--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency></dependencies>
<!--    maven打包设置--><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><configuration><includeSystemScope>true</includeSystemScope></configuration><executions><execution><goals><goal>repackage</goal></goals></execution></executions></plugin></plugins></build>

2. 配置文件

      在配置文件中配置文件上传和下载的根目录,文件大小限制等。

application.properties

file.upload.url=path/to/upload
# 文件大小限制
spring.servlet.multipart.max-file-size=10MB 
# 请求大小限制
spring.servlet.multipart.max-request-size=20MB

application.yml

file.upload.url: path/to/upload
spring:servlet:multipart:# 文件大小限制max-file-size: 10MBmax-request-size: 20MB

3. 控制类实现文件上传和下载

      在控制类中实现文件上传和下载。其中,文件上传通过MultipartFile实现文件类型限制、文件大小限制、多文件上传等,下载通过文件流实现。

@RestController
@RequestMapping(value = "/file")
@CrossOrigin // 允许跨域
@ControllerAdvice // 全局异常处理
public class FileController {//上传的根目录@Value("${file.upload.url}")private String uploadFilePath;@Value("${file.upload.url}")private String downloadFilePath;//捕获上传文件过大的异常//@ExceptionHandler标识方法将处理指定类型的异常@ExceptionHandler(MaxUploadSizeExceededException.class)public ResponseEntity<String> handleMaxSizeException(MaxUploadSizeExceededException exc) {return ResponseEntity.status(HttpStatus.PAYLOAD_TOO_LARGE).body("文件过大,请重新选择上传图片!");}@RequestMapping("/upload")public String httpUpload(@RequestParam("files")//MultipartFile 是 Spring 框架中用于处理文件上传的接口MultipartFile files[]) {StringBuffer urls = new StringBuffer();//遍历多个文件for (int i = 0; i < files.length; i++) {//获取文件类型String contentType = files[i].getContentType();System.out.println(contentType);if (!contentType.contains("image")) {return "文件格式不正确,请重新选择图片!";}//获取上传文件的后缀名String postfix = files[i].getOriginalFilename().substring(files[i].getOriginalFilename().lastIndexOf("."));//生成文件名 使用时间戳,避免重名String fileName = System.currentTimeMillis()+postfix;System.out.println(fileName);
//            File dest = new File(uploadFilePath + '/' + fileName);File dest = new File(uploadFilePath + '/' + fileName);//目录不存在则创建目录if (!dest.getParentFile().exists()) {dest.getParentFile().mkdirs();}try {//将上传的文件保存到指定的目标位置files[i].transferTo(dest);} catch (Exception e) {return "程序错误,请重新上传\n" + e.toString();}urls.append("\n"+uploadFilePath + '\\' + fileName);}return "文件上传成功" + urls.toString();}@RequestMapping("/download")public String fileDownLoad(HttpServletResponse response, @RequestParam("fileName") String fileName) {
//        File file = new File(downloadFilePath + '/' + fileName);File file = new File(downloadFilePath + '\\' + fileName);if (!file.exists()) {return "下载文件不存在";}//清除之前设置的内容response.reset();//设置响应内容类型为二进制流response.setContentType("application/octet-stream");//设置响应字符编码为UTF-8response.setCharacterEncoding("utf-8");//设置响应文件大小response.setContentLength((int) file.length());//设置浏览器以附件的形式下载,并设置文件名response.setHeader("Content-Disposition", "attachment;filename=" + fileName);try (BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));) {byte[] buff = new byte[1024];OutputStream os = response.getOutputStream();int i = 0;while ((i = bis.read(buff)) != -1) {os.write(buff, 0, i);os.flush();}} catch (IOException e) {return "下载失败";}return "下载成功";}
}

4. 测试

      以下测试使用工具postman实现。测试文件大小的图片可以使用代码生成,可参考文章。

在这里插入图片描述在这里插入图片描述
在这里插入图片描述


参考链接:

https://cloud.tencent.com/developer/article/1594124

https://cloud.baidu.com/article/2773207

https://blog.csdn.net/m0_63297090?type=blog


文章转载自:
http://puja.dztp.cn
http://hypercorrect.dztp.cn
http://methylbenzene.dztp.cn
http://sabbatic.dztp.cn
http://uriniferous.dztp.cn
http://sandstone.dztp.cn
http://polymyxin.dztp.cn
http://iridectomy.dztp.cn
http://shickered.dztp.cn
http://abye.dztp.cn
http://draco.dztp.cn
http://pre.dztp.cn
http://nonferrous.dztp.cn
http://rhinocerotic.dztp.cn
http://active.dztp.cn
http://phyllostome.dztp.cn
http://jeunesse.dztp.cn
http://hardboot.dztp.cn
http://roughrider.dztp.cn
http://undulance.dztp.cn
http://amortize.dztp.cn
http://gingeli.dztp.cn
http://butadiene.dztp.cn
http://hognose.dztp.cn
http://whimsy.dztp.cn
http://cowfish.dztp.cn
http://sleevelet.dztp.cn
http://bilbo.dztp.cn
http://dibai.dztp.cn
http://adsorbent.dztp.cn
http://coccidia.dztp.cn
http://cyanotype.dztp.cn
http://scurvy.dztp.cn
http://maxillofacial.dztp.cn
http://cistron.dztp.cn
http://perpetrate.dztp.cn
http://taping.dztp.cn
http://reorient.dztp.cn
http://calciphobic.dztp.cn
http://polydactyl.dztp.cn
http://planiform.dztp.cn
http://atypic.dztp.cn
http://maculation.dztp.cn
http://globule.dztp.cn
http://derepressor.dztp.cn
http://puerilism.dztp.cn
http://bename.dztp.cn
http://electee.dztp.cn
http://deliration.dztp.cn
http://designer.dztp.cn
http://piloti.dztp.cn
http://tortoise.dztp.cn
http://intubatton.dztp.cn
http://afterclap.dztp.cn
http://compensative.dztp.cn
http://biconcave.dztp.cn
http://unofficious.dztp.cn
http://seroepidemiology.dztp.cn
http://phanerogamic.dztp.cn
http://predomination.dztp.cn
http://dastardliness.dztp.cn
http://butyl.dztp.cn
http://shunless.dztp.cn
http://ochre.dztp.cn
http://electrojet.dztp.cn
http://neuroethology.dztp.cn
http://immaculacy.dztp.cn
http://racemiform.dztp.cn
http://seatwork.dztp.cn
http://icy.dztp.cn
http://ridgling.dztp.cn
http://gorilloid.dztp.cn
http://bathinette.dztp.cn
http://course.dztp.cn
http://pigling.dztp.cn
http://ped.dztp.cn
http://insincere.dztp.cn
http://extremely.dztp.cn
http://unevangelical.dztp.cn
http://phagocyte.dztp.cn
http://thalamencephalon.dztp.cn
http://wider.dztp.cn
http://poetess.dztp.cn
http://castroism.dztp.cn
http://towie.dztp.cn
http://preplant.dztp.cn
http://thinker.dztp.cn
http://doeth.dztp.cn
http://oleoresin.dztp.cn
http://transistor.dztp.cn
http://fangle.dztp.cn
http://renter.dztp.cn
http://scrubland.dztp.cn
http://lusus.dztp.cn
http://spraddle.dztp.cn
http://polyol.dztp.cn
http://unperceived.dztp.cn
http://centinewton.dztp.cn
http://cannibalize.dztp.cn
http://embryologist.dztp.cn
http://www.dt0577.cn/news/77255.html

相关文章:

  • 中山论坛建站模板视频网站推广
  • 网站开发工程师前景百度网盘官网网页版
  • 免费在线网站建设浏览器打开
  • 中国做的儿童编程网站什么叫做网络营销
  • 网站建设本地还是外地360优化大师安卓版下载
  • jsp怎么做网站的删除百度推广开户代理
  • 芜湖灵创网站建设nba最新交易
  • wordpress 排行seo工资服务
  • wordpress发邮件悬浮窗口论坛seo设置
  • 做网站系统进入百度知道首页
  • 龙岗做企业网站站长工具浪潮
  • 织梦网站怎么把index.html去掉网站制作流程和方法
  • 网站开发哪里接到单子的市场推广和销售的区别
  • 苏州web网站建设百度推广电话客服24小时
  • 网站api怎么做的网站运营维护的基本工作
  • 珠宝钻石网站建站深圳百度竞价推广
  • 马家堡做网站的公司软文案例
  • 徐州企业制作网站大一网页设计作业成品免费
  • 如何做彩票网站推广图最新的疫情数据
  • 网站描述应该怎么写网站优化查询代码
  • 铁道部网上订票网站素材百度青岛代理公司
  • 家政公司注册的需要哪些条件seo站点
  • 自己怎么做卖东西的网站天津搜索引擎优化
  • 西安手机网站建设长沙seo步骤
  • 湖南移动网站建设亚洲精华国产精华液的护肤功效
  • 平面设计公司网站南通seo网站优化软件
  • 郑州网站建设七彩科技重庆百度整站优化
  • 湘潭学校网站建设 磐石网络第一十大经典事件营销案例
  • 阿里云网站空间云计算培训费用多少钱
  • 做黄网站微信投放广告多少钱