参考:
https://blog.csdn.net/qq_25432245/article/details/84779044
https://www.cnblogs.com/kyliechen/p/10732760.html
实现:
public String add(HttpServletRequest request, HttpServletResponse response) {
//目的:通过excel表获得员工信息存储到数据库
try {
//1,创建磁盘文件工厂
DiskFileItemFactory factory = new DiskFileItemFactory();
//2,创建文件上传核心类
ServletFileUpload upload = new ServletFileUpload(factory);
//3,解析request获得文件项对象集合
List<FileItem> parseRequest = upload.parseRequest(request);
//4,遍历文件项集合
for(FileItem item : parseRequest){
//判断是否是普通文件项
boolean formField = item.isFormField();
if(!formField){
//文件上传项获得文件名称和文件内容
String file = item.getName();//获得上传文件的名字
InputStream in = item.getInputStream();//以流的方式获得文件的内容,获得输入流
Workbook workbook &