vue+springboot导入Excel表格

1.创建一个excel表格,与数据库需要的表头对应

2.(前端)导入excel的按钮
复制代码
<template class="importExcel">
  <el-button type="primary"  @click="chooseFile">导入<i class="el-icon-upload el-icon--right"></i></el-button>
  <input type="file" ref="fileInput" style="display: none"
         @change="handleFileChange" accept=".xlsx, .xls" />
</template>

显示为这样

3.按钮涉及到的方法
javascript 复制代码
chooseFile() {
  this.$refs.fileInput.click();
},
handleFileChange(event) {
  const file = event.target.files[0];
  if (file) {
    this.$message('所选文件:' + file.name);
    const fData = new FormData();
    fData.append('fData', file);
    const 
    axios.post("http://localhost:8081/probationaryPartyMember/importExcel", fData).then((response) => {
      console.log(response.data);
      if(response.data.code === 1) {
        // 处理成功响应
        this.$message('文件上传成功', response);
        this.formInline.name = '';
        this.formInline.studentId = '';
        this.formInline.reply = '';
        this.getList();
      }else {
        if (response.data.data === 2) {
          this.$message("编号为" + response.data.data + "的预备党员已存在,请删除这条数据上传之后的数据");
          if (response.data.data === 0) {
            this.$message("申请编号为" + response.data.data + "及之后的数据上传失败");
          }
        }
      }
    }).catch((error) => {
          // 处理错误
          console.error('文件上传失败', error);
          // 显示一个友好的错误消息给用户
          this.$message.error('文件上传失败,请检查文件并重试');
        });
  }


},
4 . (后端) 导入依赖
java 复制代码
 <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>easyexcel</artifactId>
            <version>3.1.1</version>
        </dependency>
5.创建一个实体类
6.创建一个类,继承ReadListener接口
7.在其他类中调用上述方法
8.得到列表,进行后续操作
相关推荐
rfidunion2 小时前
springboot+VUE+部署(12。Nginx和前端配置遇到的问题)
前端·vue.js·spring boot
vx-Biye_Design3 小时前
servlet家政公司管理系统-计算机毕业设计源码01438
java·vue.js·spring·servlet·tomcat·maven·mybatis
FYKJ_20103 小时前
springboot大学校园论坛管理系统--附源码42669
java·javascript·spring boot·python·spark·django·php
QQ24391973 小时前
语言在线考试与学习交流网页平台信息管理系统源码-SpringBoot后端+Vue前端+MySQL【可直接运行】
前端·spring boot·sql·学习·java-ee
毕设源码-小云学姐3 小时前
计算机毕业设计springboot医疗档案管理系统 基于 SpringBoot 的电子医疗档案管理系统的设计与实现 SpringBoot 框架下的医疗档案信息化管理系统开发
spring boot·后端·课程设计
想不明白的过度思考者3 小时前
JavaEE进阶 ——【SpringBoot 快速上手】从环境搭建到HelloWorld实战
java·spring boot·spring·java-ee
那我掉的头发算什么3 小时前
【SpringBoot】一篇文章讲清楚拦截器所有知识
java·spring boot·后端·spring
百锦再5 小时前
Java中的反射机制详解:从原理到实践的全面剖析
java·开发语言·jvm·spring boot·struts·spring cloud·kafka
树码小子7 小时前
图书管理系统(5)强制登陆(后端实现)
spring boot·mybatis·图书管理系统
丹牛Daniel7 小时前
Java解决HV000183: Unable to initialize ‘javax.el.ExpressionFactory‘
java·开发语言·spring boot·tomcat·intellij-idea·个人开发