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

秦皇岛网站制作公司淘宝seo对什么内容优化

秦皇岛网站制作公司,淘宝seo对什么内容优化,东莞做展示网站的公司,深圳分销网站设计价格配置文件上传属性: 在application.properties文件中配置文件上传的属性,包括上传目录的路径、文件大小限制等。 spring.servlet.multipart.max-file-size10MB spring.servlet.multipart.max-request-size10MB处理文件上传请求 上传的文件按照日期进行…

配置文件上传属性:

在application.properties文件中配置文件上传的属性,包括上传目录的路径、文件大小限制等。

spring.servlet.multipart.max-file-size=10MB
spring.servlet.multipart.max-request-size=10MB

处理文件上传请求

上传的文件按照日期进行归类,使用UUID给文件重命名

    @PostMapping("/upload/")@ResponseBodypublic  Response upload(MultipartFile file) {// 验证是否有文件if(file == null || file.isEmpty()){return Response.newFail("Upload failed, please select file",400);}// 文件保存目录SimpleDateFormat sdf = new SimpleDateFormat("/yyyy/MM/dd/");String format = sdf.format(new Date());String filePath = "D:/flies/springboot/"+format;// 验证文件夹File folder = new File(filePath);if (!folder.exists()) {folder.mkdirs();}// 文件名String fileName = UUID.randomUUID() + file.getOriginalFilename();filePath = filePath  + fileName;File saveFile = new File(filePath);try {file.transferTo(saveFile);return  Response.newSuccess("Upload successful");} catch (IOException e) {e.printStackTrace();return  Response.newFail("Upload failed",50001);}}

文件过大

如果遇到文件过大出现413状态码无结果
需要统一返回json,可以参考
Springboot封装统一返回结果及全局异常处理

配置文件保存路径

可以在配置中保存文件的存放位置,方便更改

配置文件

application.properties文件添加需要的配置

file.path=D:\\flies\\springboot\\

@ConfigurationProperties 注解

使用注解@ConfigurationProperties将配置项和实体Bean关联起来,实现配置项和实体类字段的关联,读取配置文件数据。

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;@Data
@Component
@ConfigurationProperties(prefix = "file")
public class FileConfig {private String path;
}

使用

获取配置信息

FileConfig fileConfig = new FileConfig();
// 文件保存目录
String filePath = fileConfig.getPath();
    @PostMapping("/upload/")@ResponseBodypublic  Response upload(MultipartFile file) {// 验证是否有文件if(file == null || file.isEmpty()){return Response.newFail("Upload failed, please select file",400);}FileConfig fileConfig = new FileConfig();// 文件保存目录String filePath = fileConfig.getPath();// 验证文件夹File folder = new File(filePath);if (!folder.exists()) {folder.mkdirs();}// 文件名String fileName = UUID.randomUUID() + file.getOriginalFilename();filePath = filePath  + fileName;File saveFile = new File(filePath);try {file.transferTo(saveFile);return  Response.newSuccess("Upload successful");} catch (IOException e) {e.printStackTrace();return  Response.newFail("Upload failed",50001);}}
http://www.hkea.cn/news/382663/

相关文章:

  • 深圳聘请做网站人员长春刚刚最新消息今天
  • 汽配人网做网站沈阳网站seo公司
  • 网站 短链接怎么做网站建设网站定制
  • 网站开发凭证做什么科目百度推广关键词多少合适
  • 网站正在建设 h5模板新闻热点
  • 龙岗公司网站建设怎么上百度搜索
  • 七米网站建设网站自动推广软件免费
  • 余姚公司做网站跨境电商怎么做
  • 顺义哪有做网站厂家百度快照在哪里找
  • 深圳南山网站建设重庆seo黄智
  • 教育微网站建设我要学电脑哪里有短期培训班
  • 民宿预订网站制作推广方案怎么做
  • 做网站都要掌握什么网页模版
  • 网站怎么做qq微信登陆长沙优化网站哪家公司好
  • 为什么上不了建设银行个人网站漳州网络推广
  • 天津手机网站建站培训代运营公司可靠吗
  • 网站制作的一般步骤长春网站优化平台
  • Python做网站 性能上海seo培训中心
  • 网上投诉平台公众号排名优化
  • 网页模板网站推荐媒体公关是做什么的
  • 泰安的网站建设公司爱站网域名查询
  • 台州椒江网站制作公司广告推销
  • 南康做网站合肥seo招聘
  • 成都网站建设定长沙专业网站制作
  • 有什么网站是python做的如何自己开发一个平台
  • 网站建设标志设计北京网站优化公司
  • 图标使用wordpress杭州seo博客
  • 企业网站如何做推广竞价推广托管公司介绍
  • 网站如何做微信登录seo公司 杭州
  • 中山里水网站建设软文广告案例分析