代码生成界面 /tool/gen
操作步骤
- 新增学生表
DROP TABLE IF EXISTS sys_student;
CREATE TABLE sys_student (
student_id INT(11) AUTO_INCREMENT COMMENT '编号',
student_name VARCHAR(30) DEFAULT '' COMMENT '学生名称',
student_age INT(3) DEFAULT NULL COMMENT '年龄',
student_sex CHAR(1) DEFAULT '0' COMMENT '性别(0男 1女 2未知)',
student_status CHAR(1) DEFAULT '0' COMMENT '状态(0正常 1停用)',
student_birthday DATETIME COMMENT '生日',
remark VARCHAR(500) DEFAULT NULL COMMENT '备注',
PRIMARY KEY (student_id)
) ENGINE=INNODB AUTO_INCREMENT=1 COMMENT = '学生信息表';
- 登录系统(系统工具 -> 代码生成 -> 导入对应表)
- 代码生成列表中找到需要表(可预览、修改、删除生成配置)
- 点击生成代码会得到一个ruoyi.zip 执行
sql
文件,按照包内目录结构复制到自己的项目中即可
GenController控制代码生成操作处理
package com.ruoyi.generator.controller;
import java.io.IOException;
import java.util.List;
import java.util.Map;
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.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
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.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.security.PermissionUtils;
import com.ruoyi.generator.domain.GenTable;
import com.ruoyi.generator.domain.GenTableColumn;
import com.ruoyi.generator.service.IGenTableColumnService;
import com.ruoyi.generator.service.IGenTableService;
@Controller
@RequestMapping("/tool/gen")
public class GenController extends BaseController
{
private String prefix = "tool/gen";
@Autowired
private IGenTableService genTableService;
@Autowired
private IGenTableColumnService genTableColumnService;
@RequiresPermissions("tool:gen:view")
@GetMapping()
public String gen()
{
return prefix + "/gen";
}
导入表 /too;/gen/improtTable
@RequiresPermissions("tool:gen:list")
@GetMapping("/importTable")
public String importTable()
{
return prefix +