上传文件1 .添加依赖关系
从属关系! - https://mvn存储库.com/artifact/commons-file upload/commons-file upload-- dependencygroupidcommons-file upload ad dependencydependencygroupidorg.spring framework/groupidartifactidspring-web/artifactidspring version/dependencydependend groupidartifactidspring-web MVC/artifactidversion5.1.3. re sion
@ controllerpublicclassfileupload { @ request mapping ('/upload ' ) public string upload (多参数文件) throwsioexceptiion }} 3.web.xml
we B- app显示- namearchetypecreatedwebapplication/display-nameservletservlet-namedispatcherservlet/servlet-name servlet-class org.spring框架. web.servlet.dispatcher servlet/servlet-class init-param param-name param-name param-value class path : base-file.XML/param-value/init-param 服务器服务器映射服务器名称服务器名称URL-pattern *.action/URL-pattern/servlet-mapping/we B- app4.
? XML版本=' 1.0 '编码=' utf-8 '? beans xmlns=' http://www.spring框架. org/schema/beans ' xmlns 3360 xsi=' http://www.w3.org/2001/XML方案-实例' xmlns : context=' http://www.spring framework.org /方案/context ' xsi :方案位置=' ' beans/spring-beans.xsd 3358 www.spring framework.org/schema/content context/spring-context.xsd ' context 3360 cont beanid='multipartresolver -设置上载文件的大小--property name=' maxuploadsize ' value=' 100000 '/property name=' DDE
! doctypehtmlhtmllang=' en ' headmetacharset=' utf-8 ' title title/title/headbodyformaction='/upload.action ' en ction form-data ' method=' post ' input type=' file ' name=' file ' br input type=' submit ' value=
@ controllerpublicclassfiledownload { @请求映射('/download ' ) publicresponseentitybyte [ ] download ) } throwsioexion Content-Disposition :这是目前的是文件下载filename是你下载的文件名http headers.add (content-disposition )、' attachment; filename=tiedan.png '; returnnewresponseentity (fileutils.readfiletobytearray (new file ) ) d:/test.png )、httpHeaders、httpstatus.) }结构: