1.引入ExcelKit的依赖
com.wuwenze
ExcelKit
2.0.71
2.实体类
public class User {
@ExportConfig(value = "UID", width = 150)
private Integer uid;
@ExportConfig(value = "用户名", width = 200)
private String username;
@ExportConfig(value = "密码(不可见)", width = 120, isExportData = false)
private String password;
@ExportConfig(value = "昵称", width = 200)
private String nickname;
private Integer age;
// getter setter...
}
3.Controller
public void exportExcel(QueryRequest request, ToticLog obj, HttpServletResponse response) throws CommonException {
try {
List toticLog = iToticLogService.list(obj);
ExcelKit.$Export(ToticLog.class, response).downXlsx(toticLog, false);
} catch (Exception e) {
String message = “导出Excel失败”;
log.error(message, e);
throw new CommonException(message);
}
}