头图

problem

  • Poi-tl in HttpServletResponse export Word garbled problem:

    • file name is in Chinese, and the Chinese name is garbled
    • the exported file to download garbled

      reason

  • Chinese garbled file name:

    • No encoding rules for filenames set
  • file download garbled characters:

    • Controller layer in RESTful incorrectly uses PostMapping

      Solution

  • file name is garbled:

    String attachName = new String(("Xxx.docx").getBytes(), "ISO-8859-1");
    response.setHeader("Content-disposition", "attachment;filename=" + attachName);
  • File download garbled characters:

    • The interface exported by Word uses ==GetMapping==
    • Use ==Request URL== to get file download
  • Get Word template path:

    • Use the InputStream tool class to get the path of the file

      // 使用InputStream流获取Word模版
      InputStream fis = this.getClass().getResourceAsStream("/template/xxxTemplate.docx");

      Summarize

  • Learn the usage of the framework according to the framework documentation, and then develop related functions according to the example
  • Pay attention to the usage notes and advanced usage in the framework
  • Combine advanced usage with project practice and choose the best solution for use

攻城狮Chova
67 声望8 粉丝

一位有自我修养的攻城狮。