CommonsMultipartFile---用Spring实现文件上传
CommonsMultipartFile
Spring提供的读取文件的类,使用方便,依赖spring-web-3.1.2.RELEASE.jar
包路径:
java.lang.Object
org.springframework.web.multipart.commons.CommonsMultipartFile
- 方法汇总:
byte[] | getBytes() |
Return the contents of the file as an array of bytes. |
String |
getContentType() |
Return the content type of the file. |
FileItem | getFileItem() |
Return the underlying org.apache.commons.fileupload.FileItem instance |
InputStream | getInputStream() |
Return an InputStream to read the contents of the file from. |
String | getName() |
Return the name of the parameter in the multipart form. |
String | getOriginalFilename() |
Return the original filename in the client's filesystem. |
long | getSize() |
Return the size of the file in bytes. |
String | getStorageDescription() |
Return a description for the storage location of the multipart content. |
protected boolean |
isAvailable() |
Determine whether the multipart content is still available. |
boolean | isEmpty() |
Return whether the uploaded file is empty, that is, either no file has been chosen in the multipart form or the chosen file has no content. |
voic | transferTo(File dest) |
Transfer the received file to the given destination file. |
使用方法:
- 1.spring配置文件配置文件上传解析器
- <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <property name="defaultEncoding" value="utf-8"></property> <property name="maxUploadSize" value="90000000" /> <property name="uploadTempDir" value="uploadFiles"></property> </bean>
- 2.html写法注意两点
- a.input类型为file:<input type="file" name="sealPfxFile" id="sealPfxFile" size="24" />
- b.form中增加参数enctype="multipart/form-data":
- <form id="addSeal" name="addSeal" action="${root}/seal/o_add.do" enctype="multipart/form-data" method="post">
- 3.Service的写法(注意与html中定义的名称相同即可通过get方法取得需要的内容)
- public String doAction(@RequestParam("sealPfxFile") CommonsMultipartFile sealPfxFile, Seal seal, ModelMap modelMap, HttpServletRequest request) throws Exception {
- //上传文件名
- String fileName = sealPfxFile.getFileItem().getName();
- //上传文件流
- InputStream is = sealPfxFile.getInputStream();
- }
CommonsMultipartFile---用Spring实现文件上传的更多相关文章
- Spring MVC 笔记 —— Spring MVC 文件上传
文件上传 配置MultipartResolver <bean id="multipartResolver" class="org.springframework.w ...
- spring实现文件上传(图片解析)
合抱之木,生于毫末,千里之行,始于足下,要想了解spring的文件上传功能,首先要知道spring是通过流的方式将文件进行解析,然后上传.那么是不是所有需要用的文件上传的地方都要写一遍文件解析器呢? ...
- Spring Boot 文件上传原理
首先我们要知道什么是Spring Boot,这里简单说一下,Spring Boot可以看作是一个框架中的框架--->集成了各种框架,像security.jpa.data.cloud等等,它无须关 ...
- Spring MVC文件上传教程 commons-io/commons-uploadfile
Spring MVC文件上传教程 commons-io/commons-uploadfile 用到的依赖jar包: commons-fileupload 1.3.1 commons-io 2.4 基于 ...
- spring boot文件上传、下载
主题:Spring boot 文件上传(多文件上传)[从零开始学Spring Boot]http://www.iteye.com/topic/1143595 Spring MVC实现文件下载http: ...
- springboot成神之——spring的文件上传
本文介绍spring的文件上传 目录结构 配置application DemoApplication WebConfig TestController 前端上传 本文介绍spring的文件上传 目录结 ...
- 【Java Web开发学习】Spring MVC文件上传
[Java Web开发学习]Spring MVC文件上传 转载:https://www.cnblogs.com/yangchongxing/p/9290489.html 文件上传有两种实现方式,都比较 ...
- Spring mvc文件上传实现
Spring mvc文件上传实现 jsp页面客户端表单编写 三个要素: 1.表单项type="file" 2.表单的提交方式:post 3.表单的enctype属性是多部分表单形式 ...
- 用Spring实现文件上传(CommonsMultipartFile)!
2012-02-16 18:10:26| 分类: 计算机--JAVA EE-|字号 订阅 spring中的文件上传实际比较容易1.页面中<html> <body> & ...
- SpringMVC , Spring , MyBatis 文件上传
学习一下文件上传下载,为图片上传做准备,感觉有一个世纪没玩过上传下载了,边敲代码边记录,请各路大神指教: 参考:http://blog.csdn.net/wjycgl/article/details/ ...
随机推荐
- map 解析
Observable.of(1, 2, 3) .map { $0 * $0 } .subscribe(onNext: { print($0) }) .disposed(by: disposeBag) ...
- Kafka学习笔记(2)----Kafka的架构
1. 架构图 一个Kafka集群中包含若干个Broker(消息实例),Kafka支持Broker横向扩展,Broker越多,吞吐量越大,同时也包含了若干个Producer(可以是web前端产生的Pag ...
- 提示 npm update check failed
执行npm命令时出现以下提示 虽然不影响代码运行,但总觉得看了很碍事, 查找资料后发现是因为文件夹权限的问题, .config / configstore文件夹中包含一个文件:update-notif ...
- 克隆CentOS 6.9 配置静态IP,重启网络服务时报错
克隆的CentOS 6.9 第一次开机时,VMware workstation会为新虚拟机自动生成新mac地址,导致虚拟机配置文件中mac地址与虚拟机新mac地址不一致. 解决方法:1. 修改网卡配置 ...
- pandaboy Merry Christmas
- let var const
eslint要求变量声明使用const的,而不是let和var如果可能的话. 如果一个变量只有在声明时才被赋值一次,那么应该使用'const' 'use strict';(function() { v ...
- Python数据结构1-----基本数据结构和collections系列
1.基本数据结构 整型.浮点型.字符串.元祖.列表.字典.集合 2.高级数据结构 (collections模块) (1)计数器(counter):对字典的补充,用于追踪值的出现次数. [具备字典所有的 ...
- 洛谷—— P1262 间谍网络
https://www.luogu.org/problem/show?pid=1262 题目描述 由于外国间谍的大量渗入,国家安全正处于高度的危机之中.如果A间谍手中掌握着关于B间谍的犯罪证据,则称A ...
- JavaScript替换字符串中最后一个字符
1.问题背景 在一个输入框中,限制字符串长度为12位.利用键盘输入一个数字,会将字符串中最后一位替换,比方:111111111111.再输入一个3,会显示111111111113 2.详细实现 < ...
- Android 开源项目android-open-project解析之(二) GridView,ImageView,ProgressBar,TextView
五.GridView StaggeredGridView 同意非对齐行的GridView,类似Pinterest的瀑布流.而且跟ListView一样自带View缓存,继承自ViewGroup 项目地址 ...