Commit b0c53197 authored by yanzg's avatar yanzg

Excel导出功能

parent 00cec6ed
......@@ -4,9 +4,10 @@ import com.yanzuoguang.db.impl.DbRow;
/**
* Excel导出接口
*
* @author 颜佐光
*/
public interface ExcelDao {
public interface ExcelDao<T extends Object, M extends Object> {
/**
* 循环处理每行数据
......@@ -14,5 +15,5 @@ public interface ExcelDao {
* @param excel excel对象
* @param cond 条件参数
*/
void export(DbRow excel, Object cond);
void export(DbRow<M> excel, T cond);
}
......@@ -55,31 +55,31 @@ public class ExcelHttp<T extends Object> extends ExcelConsole<T> {
* @param downFileName 下载文件名
*/
public ExcelHttp down(HttpServletResponse response, String downFileName) throws IOException {
if(StringHelper.isEmpty(downFileName)){
if (StringHelper.isEmpty(downFileName)) {
downFileName = this.getConfig().getFileName();
}
HttpFileHelper.localToDown(this.getFileName(),downFileName,response);
HttpFileHelper.localToDown(this.getFileName(), downFileName, response);
return this;
}
/**
* 导出数据
*
* @param req 请求对接
* @param req 请求对接
* @param response 输出结果
*/
public static void export(ExportBase req, HttpServletResponse response,ExcelDao excelDao) {
ExcelHttp excel = new ExcelHttp<>(req.getConfig());
public static <T extends Object, M extends Object> void export(ExportBase<T> req, HttpServletResponse response, ExcelDao<T, M> excelDao) {
ExcelHttp<M> excel = new ExcelHttp<>(req.getConfig());
try {
excel.open();
excelDao.export(excel, req.getCond());
excel.save();
excel.down(response);
} catch (IOException e) {
} catch (IOException e) {
e.printStackTrace();
throw new CodeException("下载失败",e);
}finally {
throw new CodeException("下载失败", e);
} finally {
// 删除生成的临时文件
excel.remove();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment