使用hutool工具进行导入导出excel表格(post补充)

前台调用
exportDetail(r){

      let listMap = [];

      var myMap1 = {bar:"foo",bar1: "foo1",bar2: "foo2"}
      var myMap2 = {bar:"foo_myMap2",bar1: "foo1_myMap2",bar2: "foo3_myMap2"}

      listMap.push(myMap1);
      listMap.push(myMap2);
      console.log(listMap)


      return request({
        url: "/zhengxie/cppccproposal/exportExample22",
        method: "post",
        responseType: "blob",
        data: listMap
      }).then(response => {
        // console.log(response)
        const fileName = "提案详细导出"

        // 处理返回的文件流
        const blob = response.data;
        if (blob && blob.size === 0) {
          this.$notify.error("内容为空,无法下载");
          return;
        }
        const link = document.createElement("a");
        link.href = window.URL.createObjectURL(blob);
        link.download = fileName;
        document.body.appendChild(link);
        link.click();
        window.setTimeout(function() {
          window.URL.revokeObjectURL(blob);
          document.body.removeChild(link);
        }, 0);

      });

    }

参数

	/**
	 导出22
	 */
	@PostMapping("/exportExample22")
	@Inner(false)
	public void exportExample22(@RequestBody List<Map<String,Object>> lstMap, HttpServletResponse response) throws IOException {

		int  i= 11;
		String sSql = "";

	}
Map封装  前台
onExport() {
      const params = this.$refs.list.option.params;
      //console.log(params)
      // downBlobFile(
      //   "/aims/overseagoods/export",
      //   params,
      //   "海外仓货物管理.xlsx"
      // );

      this.downBlobFilePost(
        "/aims/overseagoods/exOverseaGoods",
        params,
        "海外仓货物导出.xlsx"
      );

    },

    downBlobFilePost(url, query, fileName) {
      return request({
        url: url,
        method: 'post',
        responseType: 'blob',
        data: query
      }).then(response => {
        // 处理返回的文件流
        const blob = response.data
        if (blob && blob.size === 0) {
          this.$notify.error('内容为空,无法下载')
          return
        }
        const link = document.createElement('a')
        link.href = URL.createObjectURL(blob)
        link.download = fileName
        document.body.appendChild(link)
        link.click()
        window.setTimeout(function() {
          URL.revokeObjectURL(blob)
          document.body.removeChild(link)
        }, 0)
      })
    }

后台
    @PostMapping("/exOverseaGoods")
    @Inner(false)
    public void exOverseaGoods(@RequestBody Map<String,Object> mp, HttpServletResponse response) throws IOException {

        int  i= 11;
        String sSql = "";

    }

posted @ 2022-10-18 15:58  寒冷的雨呢  阅读(246)  评论(0编辑  收藏  举报