jeecgboot 导入文档

20 篇文章 1 订阅

导入

<template>
  <div class="clearfix">
    <a-upload :fileList="fileList" :remove="handleRemove" :beforeUpload="beforeUpload">
      <a-button> <a-icon type="upload" /> Select File </a-button>
    </a-upload>
    <a-button
      type="primary"
      @click="handleUpload"
      :disabled="fileList.length === 0"
      :loading="uploading"
      style="margin-top: 16px"
    >
      {{ uploading ? 'Uploading' : 'Start Upload' }}
    </a-button>
  </div>
</template>
<script>
import reqwest from 'reqwest';
export default {
  data() {
    return {
      fileList: [],
      uploading: false,
    };
  },
  methods: {
    handleRemove(file) {
      const index = this.fileList.indexOf(file);
      const newFileList = this.fileList.slice();
      newFileList.splice(index, 1);
      this.fileList = newFileList;
    },
    beforeUpload(file) {
      this.fileList = [...this.fileList, file];
      return false;
    },
    handleUpload() {
      const { fileList } = this;
      const formData = new FormData();
      fileList.forEach(file => {
        formData.append('files[]', file);//后面再加上token
      });
      this.uploading = true;

      // You can use any AJAX library you like
      request({
        url: 'https://www.mocky.io/v2/5cc8019d300000980a055e76',
        method: 'post',
        processData: false,
        data: formData,
        success: () => {
          this.fileList = [];
          this.uploading = false;
          this.$message.success('upload successfully.');
        },
        error: () => {
          this.uploading = false;
          this.$message.error('upload failed.');
        },
      });
    },
  },
};
</script>
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你可以按照以下步骤使用 JeecgBoot 导入 Excel 数据: 1. 创建一个实体类,用于映射 Excel 表格中的数据字段。确保实体类的属性与 Excel 表格的列名一致。 2. 在控制器类中编写一个方法,用于处理上传的 Excel 文件。你可以使用 Apache POI 或 EasyExcel 等库来读取 Excel 文件数据。 例如,使用 EasyExcel 库可以按照如下方式读取 Excel 文件数据: ```java @PostMapping("/import") public void importExcel(MultipartFile file) { try { EasyExcel.read(file.getInputStream(), YourEntityClass.class, new YourDataListener()) .sheet().doRead(); } catch (IOException e) { // 处理异常 } } ``` 3. 创建一个数据监听器类 `YourDataListener`,继承 `AnalysisEventListener` 并重写相关方法。在 `invoke()` 方法中处理每一行的数据。 ```java public class YourDataListener extends AnalysisEventListener<YourEntityClass> { private List<YourEntityClass> dataList = new ArrayList<>(); @Override public void invoke(YourEntityClass data, AnalysisContext context) { dataList.add(data); // 处理每一行的数据,可以在这里进行业务逻辑处理或保存到数据库 } @Override public void doAfterAllAnalysed(AnalysisContext context) { // 解析完成后的操作,如保存数据到数据库 } } ``` 4. 在前端页面中添加一个文件上传的表单,并将文件提交给上述控制器中的导入方法。 ```html <form action="/import" method="post" enctype="multipart/form-data"> <input type="file" name="file" /> <input type="submit" value="导入" /> </form> ``` 这样,当你选择并提交一个 Excel 文件时,JeecgBoot 将会读取文件中的数据,并通过数据监听器进行处理。你可以在监听器中对每一行的数据进行相应的操作,比如保存到数据库中。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值