前情提要
现在大多数的web开发基本都会用到文件上传这一个功能,文件上传分为单文件上传和多文件上传,下面就一一讲解一下通过SpringBoot框架对两种上传的实现
SpringBoot实现单文件上传
首先建立一个html界面,包含一个form文件上传表单,代码如下:
<!DOCTYPE html>
<html lang="en">
<head>
<title>文件上传界面</title>
</head>
<body>
<form enctype="multipart/form-data" method="post" action="/upload">
选择文件:<input type="file" name="files" />
<br />
<button type="submit">上传</button>
<span> </span>
<button type="reset">重选</button>
</form>
</body>
</html>
然后编写/pload的请求处理控制类,实现代码如下,在代码中进行详细注释:
package org.framework.demo.section1;
import org