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/ ...
随机推荐
- 原生sql的各种问题
1.nutz有方法自动根据数据库建models吗?2.select * from a a没有建相应的models怎么取结果?3.可以直接操作result,而不是在callback里面设置吗? wend ...
- 关于layui 三级联动 渲染报错解决方法
/** * 时间:2016年11月27日 * 作者:707200833 * 说明:依赖与jQuery和layui, 是基于layui开发的一个省市区联动的小插件, 使用上要基于layui的表单进行使用 ...
- Chernobyl’ Eagle on a Roof(鹰蛋坚固度)
链接 Chernobyl’ Eagle on a Roof 题意 引用论文题意:有一堆共 M 个鹰蛋,一位教授想研究这些鹰蛋的坚硬度 E.他是通过不断从一幢 N 层的楼上向下扔鹰蛋来确定 E 的.当鹰 ...
- java equals的用法
equals方法,用于比较两个对象是否相同,它其实就是使用两个对象的内存地址在比较.Object类中的equals方法内部使用的就是==比较运算符. package Xuexi; public cla ...
- 【转】VGG网络结构及参数
VGG网络 VGG16输入224*224*3的图片,经过的卷积核大小为3x3x3,stride=1,padding=1,pooling为采用2x2的max pooling方式: 1.输入224x2 ...
- UNIX时间转换ASP代码.txt
'参数:strTime:要转换的时 间:intTimeZone:该时间对应的时区 '返回值:strTime相对于1970年1月1日午夜0点经过的秒数 '示例:ToUnixTime("2008 ...
- 原生js模拟双色球
<!DOCTYPE html><html> <head> <meta charset="utf-8" /> <title> ...
- 搞定PHP面试 - 运算符知识点整理
一.算术运算符 1. 概览 例子 名称 结果 $a + $b 加法 $a 和 $b 的和. $a - $b 减法 $a 和 $b 的差. $a * $b 乘法 $a 和 $b 的积. $a / $b ...
- 在 vue-test-utils 中 mock 全局对象
vue-test-utils 提供了一种 mock 掉 Vue.prototype 的简单方式,不但对测试用例适用,也可以为所有测试设置默认的 mock. mocks 加载选项 mocks 加载选项 ...
- python之简述上下文管理
上下文管理器 原理 代码讲解 原理 上下文管理能保证资源会被正确回收,即保证退出步骤的执行.其用处最多的是,作为确保资源被正确回收的一种方式. 一种重复使用的 try-except-finally 结 ...