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

商务网站建设与维护实训报告比较好的网站建设公司电话

商务网站建设与维护实训报告,比较好的网站建设公司电话,佛山seo优化外包,网站建设预付流程这篇文章算是一篇水文#xff0c;因为也没啥好讲的#xff0c;在Spring Boot中#xff0c;上传文件是我们常常做的#xff0c;包括我们在实际开发过程中#xff0c;我们也经常碰到与文件上传有关的功能#xff0c;这也算是我们常用的一个功能了#xff0c;毕竟作为开发者…这篇文章算是一篇水文因为也没啥好讲的在Spring Boot中上传文件是我们常常做的包括我们在实际开发过程中我们也经常碰到与文件上传有关的功能这也算是我们常用的一个功能了毕竟作为开发者我们避免不了与各种文件打交道一般文件上传是我们最常见的一种方式例如我们对Excel数据的解析入库图片的裁剪都需要我们先将文件上传之后再对文件进行解析。 注意本篇博客主要适合初学者如果不感兴趣可以移步了。 单文件上传 本篇我将采用Thymeleaf模版引擎进行故而第一步我们还是引入相关依赖。 dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-thymeleaf/artifactId/dependencydependencygroupIdorg.projectlombok/groupIdartifactIdlombok/artifactIdscopeprovided/scope/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-test/artifactIdscopetest/scope/dependency 在application.properties文件中配置存放地址以及允许上传的文件的大小 server.port1243 spring.servlet.multipart.max-file-size2MB spring.servlet.multipart.max-request-size2MBfile.upload.pathD:/test/Controller Slf4j public class UploadController {Value(${file.upload.path})private String path;GetMapping(/)public String uploadPage() {return upload;}PostMapping(/upload)ResponseBodypublic String create(RequestPart MultipartFile file) throws IOException {String fileName file.getOriginalFilename();String filePath path fileName;File dest new File(filePath);Files.copy(file.getInputStream(), dest.toPath());return 上传本地文件路径: dest.getAbsolutePath();}}!DOCTYPE html html head langenmeta charsetUTF-8 /title文件上传页面/title /head body h1文件上传页面/h1 form methodpost action/upload enctypemultipart/form-data选择要上传的文件input typefile namefilebrhrinput typesubmit value提交 /form /body /html通过浏览器localhost:1243 这里仅仅是一个案例在实际开发过程中我们需要考虑更多比如文件上传后的文件我们需要进行相关处理一般可以添加时间日期等预防同名在分布式服务下我们需要考虑文件如何共享访问等等。 多文件上传 多文件上传其实也很简单在我们上边的基础之上进行改造就行了因为涉及到多个文件故而我们需要将上述代码进行改造如果是单个文件上传那么我们就使用一个对象就可以解决既然涉及到多个文件那么我们可以尝试使用数组对象进行。 还是之前的那样第一步先引入依赖 注意这里的依赖和上述依赖一模一样毫无变化配置文件也是。 dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-thymeleaf/artifactId/dependencydependencygroupIdorg.projectlombok/groupIdartifactIdlombok/artifactIdscopeprovided/scope/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-test/artifactIdscopetest/scope/dependencyspring.servlet.multipart.max-file-size2MB spring.servlet.multipart.max-request-size2MBserver.port1243file.upload.pathD:/test/在前端页面上我多加了一个文件提交按钮。 !DOCTYPE html html head langenmeta charsetUTF-8 /title文件上传页面/title /head body h1文件上传页面/h1 form methodpost action/upload enctypemultipart/form-data文件1input typefile namefilesbr文件2input typefile namefilesbrhrinput typesubmit value提交 /form /body /html文件上传控制类 Controller Slf4j public class UploadController {Value(${file.upload.path})private String path;GetMapping(/)public String uploadPage() {return upload;}PostMapping(/upload)ResponseBody//主要这里我们改造的地方由单个对象变成了数组对象public String create(RequestPart MultipartFile[] files) throws IOException {StringBuffer message new StringBuffer();//循环遍历出数组对象for (MultipartFile file : files) {//为了避免文件名同名我加了日期前置你也选择精确的具体时间String date new SimpleDateFormat(yyyy-MM-dd).format(new Date());String fileName date file.getOriginalFilename();String filePath path fileName;File dest new File(filePath);Files.copy(file.getInputStream(), dest.toPath());message.append(文件上传成功 : dest.getAbsolutePath()).append(br);}return message.toString();}}也不知道怎么说其实实现一个简单的文件上传案例其实也没啥可以说的也很简单可以在以上基础之上对代码进行改造至于想改造成啥那就得看你的需求了。
http://www.dnsts.com.cn/news/243892.html

相关文章:

  • 成都制作网站asp网站怎么打开
  • 网站开发要学多久杭州软件开发公司网站
  • 新网站友链自己做头像的网站
  • 山东济宁网站建设申请个人企业邮箱
  • 建设网站需要哪些编程dede网站禁止ip访问
  • 网站制作软件手机版搭建一个小程序需要多少钱
  • 网站设计尺寸大小沈阳模板建站系统
  • 建一个网站需要什么资料如何用wordpress搭建个人博客
  • 衡水城乡建设局网站首页17网一起做网店
  • 网站建设php文件放哪里网站建设哪家go好
  • 网站后台seo优化如何做asp 网站路径泄露 解决
  • 中国水利教育培训网站wordpress 主题 试用
  • 深圳网站优化多少钱电子简历表格 个人简历
  • 自有服务器 建网站个人网站设计策划书
  • 衡水外贸网站建设太原制作网站企业
  • 如何在电脑上做物流网站做化工的网站
  • 网站开发作为固定资产怎么摊销网站怎么做动态图片
  • 网站建设的钱计入什么科目近三天发生的重要新闻
  • 如何做新增网站备案佛山外贸网站建设特色
  • 江苏营销型网站推广wordpress 获取导航
  • 建立了公司网站巴中做网站 微信开发
  • 临海营销型网站建设合伙企业怎么注册公司
  • 长沙网站建设1681989做网站什么字体
  • 专业的设计网站有哪些内容网站建设与维护招投标书
  • 珠海横琴建设局网站大连学校网站建设
  • 大连h5网站建设吕梁网站建设kuyiso
  • 哪个网站有手工活做怎么建设微信网站
  • 专门做外卖的网站上海工商网一窗通
  • 衡阳网站推广优化公司网络架构有几层
  • 环保部网站建设项目重大变动做网站 商标分类