springboot-简单测试 前端上传Excel表格后端解析数据

导入依赖

 <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>5.2.2</version>
        </dependency>

        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>5.2.2</version>
        </dependency>
<dependency>
            <groupId>cn.hutool</groupId>
            <artifactId>hutool-all</artifactId>
            <version>5.8.23</version>
        </dependency>

创建util工具包以及Excel工具类

public class ExcelUtils {
    public static void PraseExcel(InputStream inputStream){
        ExcelUtil.readBySax(inputStream,0,(sheetIndex,rowIndex,list) ->{
            System.out.println(sheetIndex);
            System.out.println(rowIndex);
            System.out.println(list);
        });
    }
}

搭建Controller层进行测试

@Controller
public class ExcelPraseController {

    @RequestMapping("/ExcelParse")
    @ResponseBody
    public String pubggupload(@RequestParam("file")MultipartFile file, Model model) throws Exception{
        String name=file.getOriginalFilename();
        System.out.println(name);
        if(!name.substring(name.length()-4).equals(".xls")){
            return "格式不正确";
        }
        ExcelUtils.PraseExcel(file.getInputStream());
        return "输出成功";
    }
}

编写前端界面

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<form method="post" enctype="multipart/form-data" action="http://localhost:8080/ExcelParse">
			<input type="file" name="file" /><input type="submit" value="上传"/>
		</form>
	</body>
</html>

功能测试

后端返回数据

相关推荐

  1. el-upload图片给SpringBoot

    2024-01-21 19:32:06       13 阅读
  2. 图片至OSS

    2024-01-21 19:32:06       35 阅读
  3. 大文件

    2024-01-21 19:32:06       10 阅读
  4. elementUI实现excel文件并

    2024-01-21 19:32:06       8 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-01-21 19:32:06       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-01-21 19:32:06       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-01-21 19:32:06       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-01-21 19:32:06       18 阅读

热门阅读

  1. 【笔记】Helm-3 主题-9 Helm高级技术

    2024-01-21 19:32:06       33 阅读
  2. QEMU源码编译CentOS

    2024-01-21 19:32:06       33 阅读
  3. 【docker】之基础篇一

    2024-01-21 19:32:06       33 阅读
  4. Template -- Vue2

    2024-01-21 19:32:06       34 阅读