mirror of https://gitee.com/y_project/RuoYi.git
抽取重复代码到一个方法
parent
7d7c052771
commit
30a7806328
|
@ -1,89 +1,94 @@
|
||||||
package com.ruoyi.generator.controller;
|
package com.ruoyi.generator.controller;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
import com.ruoyi.common.annotation.Log;
|
import com.ruoyi.common.annotation.Log;
|
||||||
import com.ruoyi.common.core.controller.BaseController;
|
import com.ruoyi.common.core.controller.BaseController;
|
||||||
import com.ruoyi.common.core.page.TableDataInfo;
|
import com.ruoyi.common.core.page.TableDataInfo;
|
||||||
import com.ruoyi.common.core.text.Convert;
|
import com.ruoyi.common.core.text.Convert;
|
||||||
import com.ruoyi.common.enums.BusinessType;
|
import com.ruoyi.common.enums.BusinessType;
|
||||||
import com.ruoyi.generator.domain.TableInfo;
|
import com.ruoyi.generator.domain.TableInfo;
|
||||||
import com.ruoyi.generator.service.IGenService;
|
import com.ruoyi.generator.service.IGenService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 代码生成 操作处理
|
* 代码生成 操作处理
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
@Controller
|
@Controller
|
||||||
@RequestMapping("/tool/gen")
|
@RequestMapping("/tool/gen")
|
||||||
public class GenController extends BaseController
|
public class GenController extends BaseController
|
||||||
{
|
{
|
||||||
private String prefix = "tool/gen";
|
private String prefix = "tool/gen";
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private IGenService genService;
|
private IGenService genService;
|
||||||
|
|
||||||
@RequiresPermissions("tool:gen:view")
|
@RequiresPermissions("tool:gen:view")
|
||||||
@GetMapping()
|
@GetMapping()
|
||||||
public String gen()
|
public String gen()
|
||||||
{
|
{
|
||||||
return prefix + "/gen";
|
return prefix + "/gen";
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresPermissions("tool:gen:list")
|
@RequiresPermissions("tool:gen:list")
|
||||||
@PostMapping("/list")
|
@PostMapping("/list")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public TableDataInfo list(TableInfo tableInfo)
|
public TableDataInfo list(TableInfo tableInfo)
|
||||||
{
|
{
|
||||||
startPage();
|
startPage();
|
||||||
List<TableInfo> list = genService.selectTableList(tableInfo);
|
List<TableInfo> list = genService.selectTableList(tableInfo);
|
||||||
return getDataTable(list);
|
return getDataTable(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成代码
|
* 生成代码
|
||||||
*/
|
*/
|
||||||
@RequiresPermissions("tool:gen:code")
|
@RequiresPermissions("tool:gen:code")
|
||||||
@Log(title = "代码生成", businessType = BusinessType.GENCODE)
|
@Log(title = "代码生成", businessType = BusinessType.GENCODE)
|
||||||
@GetMapping("/genCode/{tableName}")
|
@GetMapping("/genCode/{tableName}")
|
||||||
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());
|
*/
|
||||||
}
|
@RequiresPermissions("tool:gen:code")
|
||||||
|
@Log(title = "代码生成", businessType = BusinessType.GENCODE)
|
||||||
/**
|
@GetMapping("/batchGenCode")
|
||||||
* 批量生成代码
|
@ResponseBody
|
||||||
*/
|
public void batchGenCode(HttpServletResponse response, String tables) throws IOException
|
||||||
@RequiresPermissions("tool:gen:code")
|
{
|
||||||
@Log(title = "代码生成", businessType = BusinessType.GENCODE)
|
String[] tableNames = Convert.toStrArray(tables);
|
||||||
@GetMapping("/batchGenCode")
|
byte[] data = genService.generatorCode(tableNames);
|
||||||
@ResponseBody
|
genCode(response, data);
|
||||||
public void batchGenCode(HttpServletResponse response, String tables) throws IOException
|
}
|
||||||
{
|
|
||||||
String[] tableNames = Convert.toStrArray(tables);
|
/**
|
||||||
byte[] data = genService.generatorCode(tableNames);
|
* 生成zip文件
|
||||||
response.reset();
|
* @param response
|
||||||
response.setHeader("Content-Disposition", "attachment; filename=\"ruoyi.zip\"");
|
* @param data
|
||||||
response.addHeader("Content-Length", "" + data.length);
|
* @throws IOException
|
||||||
response.setContentType("application/octet-stream; charset=UTF-8");
|
*/
|
||||||
|
private void genCode(HttpServletResponse response, byte[] data) throws IOException {
|
||||||
IOUtils.write(data, response.getOutputStream());
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue