@Test public void testStringArrayWriteCsvFile() { String[] title = {"id" , "name"}; List<String[]> bodyList = new ArrayList<>(); String[] data = new String[2]; data[0] = "1"; data[1] = "张三"; bodyList.add(data); data = new String[2]; data[0] = "2"; data[1] = "李四"; bodyList.add(data); CsvUtil.writeCsvFile(fileName, title, bodyList); }
public static void writeCsvFile(HttpServletResponse response, HttpServletRequest request, String filename, String[] title, List<String[]> bodyList) { response.setContentType("application/octet-stream;charset=GBK"); String fileName = FileUtilies.getFileName(filename, request); response.setHeader("Content-Disposition", "attachment; filename=" + fileName + ".csv"); try (CSVWriter writer = new CSVWriter(response.getWriter())) { write(writer, title, bodyList); } catch (IOException e) { throw new RuntimeException("write csv file of response fail ", e); } }
CsvUtil { public static void writeCsvFile(HttpServletResponse response, HttpServletRequest request, String filename, String[] title, List<String[]> bodyList) { response.setContentType("application/octet-stream;charset=GBK"); String fileName = FileUtilies.getFileName(filename, request); response.setHeader("Content-Disposition", "attachment; filename=" + fileName + ".csv"); try (CSVWriter writer = new CSVWriter(response.getWriter())) { write(writer, title, bodyList); } catch (IOException e) { throw new RuntimeException("write csv file of response fail ", e); } } }
CsvUtil { public static void writeCsvFile(HttpServletResponse response, HttpServletRequest request, String filename, String[] title, List<String[]> bodyList) { response.setContentType("application/octet-stream;charset=GBK"); String fileName = FileUtilies.getFileName(filename, request); response.setHeader("Content-Disposition", "attachment; filename=" + fileName + ".csv"); try (CSVWriter writer = new CSVWriter(response.getWriter())) { write(writer, title, bodyList); } catch (IOException e) { throw new RuntimeException("write csv file of response fail ", e); } }  }
CsvUtil { public static void writeCsvFile(HttpServletResponse response, HttpServletRequest request, String filename, String[] title, List<String[]> bodyList) { response.setContentType("application/octet-stream;charset=GBK"); String fileName = FileUtilies.getFileName(filename, request); response.setHeader("Content-Disposition", "attachment; filename=" + fileName + ".csv"); try (CSVWriter writer = new CSVWriter(response.getWriter())) { write(writer, title, bodyList); } catch (IOException e) { throw new RuntimeException("write csv file of response fail ", e); } }  static void writeCsvFile(HttpServletResponse response, HttpServletRequest request,
                                    String filename, String[] title, List<String[]> bodyList); static void writeCsvFile(HttpServletResponse response, HttpServletRequest request,
			String filename, String[] title, List<T> objs, Function<T, String[]> function); static void writeCsvFile(String filename, String[] title, List<String[]> bodyList); static void writeCsvFile(String filename, String[] title, List<T> objs,
										Function<T, String[]> function); }
CsvUtil { public static void writeCsvFile(HttpServletResponse response, HttpServletRequest request, String filename, String[] title, List<String[]> bodyList) { response.setContentType("application/octet-stream;charset=GBK"); String fileName = FileUtilies.getFileName(filename, request); response.setHeader("Content-Disposition", "attachment; filename=" + fileName + ".csv"); try (CSVWriter writer = new CSVWriter(response.getWriter())) { write(writer, title, bodyList); } catch (IOException e) { throw new RuntimeException("write csv file of response fail ", e); } }  static void writeCsvFile(HttpServletResponse response, HttpServletRequest request,
                                    String filename, String[] title, List<String[]> bodyList); static void writeCsvFile(HttpServletResponse response, HttpServletRequest request,
			String filename, String[] title, List<T> objs, Function<T, String[]> function); static void writeCsvFile(String filename, String[] title, List<String[]> bodyList); static void writeCsvFile(String filename, String[] title, List<T> objs,
										Function<T, String[]> function);  }