@Data
public class ExportParamVO {
}
/**
* 不带参数,有返回值 T get();
* @param <T> 返回值类型
*/
@EqualsAndHashCode(callSuper=false)
@Builder
@Data
public class CommonExportParamVO<T> extends ExportParamVO {
private String sheetName;
private Class<?> clazz;
private Supplier<T> supplier;
}
/**
* 传一个参数带一个返回值 R apply(T t)
* @param <T> 请求参数
* @param <R> 返回值类型
*/
@EqualsAndHashCode(callSuper=false)
@Builder
@Data
public class FunctionExportParamVO<T,R> extends ExportParamVO {
private String sheetName;
private Class<?> clazz;
private T query;
private Function<T, R> function;
}
/**
* 流式导出参数,带俩参数,无返回值 void accept(T t, U u)
* @param <T> 查询参数类型
*/
@EqualsAndHashCode(callSuper=false)
@Builder
@Data
public class StreamExportParamVO<T> extends ExportParamVO {
private String sheetName;
private Class<?> clazz;
private BiConsumer<T, ResultHandler> consumer;
private T query;
}
public static void exportMultiSheetExcel(HttpServletResponse response, String fileName, ExportParamVO... vo) {
exportMultiSheetExcel(response, fileName, Lists.newArrayList(vo));
}
public static <T, R> void exportMultiSheetExcel(HttpServletResponse response, String fileName, List<ExportParamVO> voList) {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
try (ServletOutputStream os = response.getOutputStream();
ExcelWriter excelWriter = EasyExcel
.write(os)
.registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
.registerConverter(
EasyExcel+mybatisPlus流式查询导出多列excel
于 2024-07-12 10:40:33 首次发布