说明
在此工具类中使用了hutool工具包,具体依赖介绍参考官方https://www.hutool.cn/docs/#/poi/概述
以及 lombok,在实体属性中需加入@ApiModelProperty注解,代码中也有说明,有不明白的或者更好的方法欢迎留言。
/**
* @author: yang
* @Date: Create in 2020/7/16
* @Explain: 封装hutool工具类实现的导出excel功能
*/
public class ExportExcelUtil {
static final Log logger = LogFactory.get(ExportExcelUtil.class);
public static void
export(HttpServletResponse response, Class clazz, List > list) throws Exception {
if(!list.isEmpty()) {
if(!list.get(0).getClass().equals(clazz)) {
logger.error("数据类型与传入的集合数据类型不一致!数据类型:{}; 集合数据类型:{}", clazz, list.get(0).getClass());
throw new Exception("数据类型与传入的集合数据类型不一致!");
} else {
ExcelWriter writer = ExcelUtil.getWriter();