From 30a7806328959f5f0f9be3abc56b6e0739f28dc2 Mon Sep 17 00:00:00 2001 From: wangjianlong Date: Thu, 23 May 2019 19:04:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=BD=E5=8F=96=E9=87=8D=E5=A4=8D=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=88=B0=E4=B8=80=E4=B8=AA=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../generator/controller/GenController.java | 183 +++++++++--------- 1 file changed, 94 insertions(+), 89 deletions(-) diff --git a/ruoyi-generator/src/main/java/com/ruoyi/generator/controller/GenController.java b/ruoyi-generator/src/main/java/com/ruoyi/generator/controller/GenController.java index b288a6ada..7d53e0069 100644 --- a/ruoyi-generator/src/main/java/com/ruoyi/generator/controller/GenController.java +++ b/ruoyi-generator/src/main/java/com/ruoyi/generator/controller/GenController.java @@ -1,89 +1,94 @@ -package com.ruoyi.generator.controller; - -import java.io.IOException; -import java.util.List; -import javax.servlet.http.HttpServletResponse; -import org.apache.commons.io.IOUtils; -import org.apache.shiro.authz.annotation.RequiresPermissions; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.ResponseBody; -import com.ruoyi.common.annotation.Log; -import com.ruoyi.common.core.controller.BaseController; -import com.ruoyi.common.core.page.TableDataInfo; -import com.ruoyi.common.core.text.Convert; -import com.ruoyi.common.enums.BusinessType; -import com.ruoyi.generator.domain.TableInfo; -import com.ruoyi.generator.service.IGenService; - -/** - * 代码生成 操作处理 - * - * @author ruoyi - */ -@Controller -@RequestMapping("/tool/gen") -public class GenController extends BaseController -{ - private String prefix = "tool/gen"; - - @Autowired - private IGenService genService; - - @RequiresPermissions("tool:gen:view") - @GetMapping() - public String gen() - { - return prefix + "/gen"; - } - - @RequiresPermissions("tool:gen:list") - @PostMapping("/list") - @ResponseBody - public TableDataInfo list(TableInfo tableInfo) - { - startPage(); - List list = genService.selectTableList(tableInfo); - return getDataTable(list); - } - - /** - * 生成代码 - */ - @RequiresPermissions("tool:gen:code") - @Log(title = "代码生成", businessType = BusinessType.GENCODE) - @GetMapping("/genCode/{tableName}") - public void genCode(HttpServletResponse response, @PathVariable("tableName") String tableName) throws IOException - { - byte[] data = genService.generatorCode(tableName); - response.reset(); - 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()); - } - - /** - * 批量生成代码 - */ - @RequiresPermissions("tool:gen:code") - @Log(title = "代码生成", businessType = BusinessType.GENCODE) - @GetMapping("/batchGenCode") - @ResponseBody - public void batchGenCode(HttpServletResponse response, String tables) throws IOException - { - String[] tableNames = Convert.toStrArray(tables); - byte[] data = genService.generatorCode(tableNames); - response.reset(); - 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()); - } -} +package com.ruoyi.generator.controller; + +import java.io.IOException; +import java.util.List; +import javax.servlet.http.HttpServletResponse; +import org.apache.commons.io.IOUtils; +import org.apache.shiro.authz.annotation.RequiresPermissions; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import com.ruoyi.common.annotation.Log; +import com.ruoyi.common.core.controller.BaseController; +import com.ruoyi.common.core.page.TableDataInfo; +import com.ruoyi.common.core.text.Convert; +import com.ruoyi.common.enums.BusinessType; +import com.ruoyi.generator.domain.TableInfo; +import com.ruoyi.generator.service.IGenService; + +/** + * 代码生成 操作处理 + * + * @author ruoyi + */ +@Controller +@RequestMapping("/tool/gen") +public class GenController extends BaseController +{ + private String prefix = "tool/gen"; + + @Autowired + private IGenService genService; + + @RequiresPermissions("tool:gen:view") + @GetMapping() + public String gen() + { + return prefix + "/gen"; + } + + @RequiresPermissions("tool:gen:list") + @PostMapping("/list") + @ResponseBody + public TableDataInfo list(TableInfo tableInfo) + { + startPage(); + List list = genService.selectTableList(tableInfo); + return getDataTable(list); + } + + /** + * 生成代码 + */ + @RequiresPermissions("tool:gen:code") + @Log(title = "代码生成", businessType = BusinessType.GENCODE) + @GetMapping("/genCode/{tableName}") + public void genCode(HttpServletResponse response, @PathVariable("tableName") String tableName) throws IOException + { + byte[] data = genService.generatorCode(tableName); + genCode(response, data); + } + + /** + * 批量生成代码 + */ + @RequiresPermissions("tool:gen:code") + @Log(title = "代码生成", businessType = BusinessType.GENCODE) + @GetMapping("/batchGenCode") + @ResponseBody + public void batchGenCode(HttpServletResponse response, String tables) throws IOException + { + String[] tableNames = Convert.toStrArray(tables); + 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.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()); + } +}