Commit b0c53197 authored by yanzg's avatar yanzg

Excel导出功能

parent 00cec6ed
...@@ -4,9 +4,10 @@ import com.yanzuoguang.db.impl.DbRow; ...@@ -4,9 +4,10 @@ import com.yanzuoguang.db.impl.DbRow;
/** /**
* Excel导出接口 * Excel导出接口
*
* @author 颜佐光 * @author 颜佐光
*/ */
public interface ExcelDao { public interface ExcelDao<T extends Object, M extends Object> {
/** /**
* 循环处理每行数据 * 循环处理每行数据
...@@ -14,5 +15,5 @@ public interface ExcelDao { ...@@ -14,5 +15,5 @@ public interface ExcelDao {
* @param excel excel对象 * @param excel excel对象
* @param cond 条件参数 * @param cond 条件参数
*/ */
void export(DbRow excel, Object cond); void export(DbRow<M> excel, T cond);
} }
...@@ -55,10 +55,10 @@ public class ExcelHttp<T extends Object> extends ExcelConsole<T> { ...@@ -55,10 +55,10 @@ public class ExcelHttp<T extends Object> extends ExcelConsole<T> {
* @param downFileName 下载文件名 * @param downFileName 下载文件名
*/ */
public ExcelHttp down(HttpServletResponse response, String downFileName) throws IOException { public ExcelHttp down(HttpServletResponse response, String downFileName) throws IOException {
if(StringHelper.isEmpty(downFileName)){ if (StringHelper.isEmpty(downFileName)) {
downFileName = this.getConfig().getFileName(); downFileName = this.getConfig().getFileName();
} }
HttpFileHelper.localToDown(this.getFileName(),downFileName,response); HttpFileHelper.localToDown(this.getFileName(), downFileName, response);
return this; return this;
} }
...@@ -68,8 +68,8 @@ public class ExcelHttp<T extends Object> extends ExcelConsole<T> { ...@@ -68,8 +68,8 @@ public class ExcelHttp<T extends Object> extends ExcelConsole<T> {
* @param req 请求对接 * @param req 请求对接
* @param response 输出结果 * @param response 输出结果
*/ */
public static void export(ExportBase req, HttpServletResponse response,ExcelDao excelDao) { public static <T extends Object, M extends Object> void export(ExportBase<T> req, HttpServletResponse response, ExcelDao<T, M> excelDao) {
ExcelHttp excel = new ExcelHttp<>(req.getConfig()); ExcelHttp<M> excel = new ExcelHttp<>(req.getConfig());
try { try {
excel.open(); excel.open();
excelDao.export(excel, req.getCond()); excelDao.export(excel, req.getCond());
...@@ -78,8 +78,8 @@ public class ExcelHttp<T extends Object> extends ExcelConsole<T> { ...@@ -78,8 +78,8 @@ public class ExcelHttp<T extends Object> extends ExcelConsole<T> {
excel.down(response); excel.down(response);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
throw new CodeException("下载失败",e); throw new CodeException("下载失败", e);
}finally { } finally {
// 删除生成的临时文件 // 删除生成的临时文件
excel.remove(); 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