Browse Source

抽取重复代码到一个方法

pull/90/head
wangjianlong 6 years ago
parent
commit
30a7806328
  1. 17
      ruoyi-generator/src/main/java/com/ruoyi/generator/controller/GenController.java

17
ruoyi-generator/src/main/java/com/ruoyi/generator/controller/GenController.java

@ -60,12 +60,7 @@ public class GenController extends BaseController
public void genCode(HttpServletResponse response, @PathVariable("tableName") String tableName) throws IOException public void genCode(HttpServletResponse response, @PathVariable("tableName") String tableName) throws IOException
{ {
byte[] data = genService.generatorCode(tableName); byte[] data = genService.generatorCode(tableName);
response.reset(); genCode(response, data);
response.setHeader("Content-Disposition", "attachment; filename=\"ruoyi.zip\"");
response.addHeader("Content-Length", "" + data.length);
response.setContentType("application/octet-stream; charset=UTF-8");
IOUtils.write(data, response.getOutputStream());
} }
/** /**
@ -79,6 +74,16 @@ public class GenController extends BaseController
{ {
String[] tableNames = Convert.toStrArray(tables); String[] tableNames = Convert.toStrArray(tables);
byte[] data = genService.generatorCode(tableNames); byte[] data = genService.generatorCode(tableNames);
genCode(response, data);
}
/**
* 生成zip文件
* @param response
* @param data
* @throws IOException
*/
private void genCode(HttpServletResponse response, byte[] data) throws IOException {
response.reset(); response.reset();
response.setHeader("Content-Disposition", "attachment; filename=\"ruoyi.zip\""); response.setHeader("Content-Disposition", "attachment; filename=\"ruoyi.zip\"");
response.addHeader("Content-Length", "" + data.length); response.addHeader("Content-Length", "" + data.length);

Loading…
Cancel
Save