RuoYi-Vue-Plus (Velocity 代码生成使用以及代码逻辑)

一、配置文件

1-配置文件: src/main/resources/generator.yml 

2-配置生成表的基础信息:包路径 前缀规则等

# 代码生成
gen: 
  # 作者
  author: ruoyi
  # 默认生成包路径 system 需改成自己的模块名称 如 system monitor tool
  packageName: com.ruoyi.system
  # 自动去除表前缀,默认是false
  autoRemovePre: false
  # 表前缀(生成类名不会包含表前缀,多个用逗号分隔)
  tablePrefix: sys_

  配置类:GenConfig

 路径 : src/main/java/com/ruoyi/generator/config/GenConfig.java

package com.ruoyi.generator.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

/**
 * 读取代码生成相关配置
 *
 * @author ruoyi
 */
@Component
@ConfigurationProperties(prefix = "gen")
@PropertySource(value = {"classpath:generator.yml"}, encoding = "UTF-8")
public class GenConfig {

    /**
     * 作者
     */
    public static String author;

    /**
     * 生成包路径
     */
    public static String packageName;

    /**
     * 自动去除表前缀,默认是false
     */
    public static boolean autoRemovePre;

    /**
     * 表前缀(类名不会包含表前缀)
     */
    public static String tablePrefix;

    public static String getAuthor() {
        return author;
    }

    @Value("${author}")
    public void setAuthor(String author) {
        GenConfig.author = author;
    }

    public static String getPackageName() {
        return packageName;
    }

  //省略。。。。。。。。
}

二、导入表逻辑

功能:导入需要生成的表数据到以下2张表

          gen_table 导入的表

         gen_table_column  导入的表列名

页面位置:src/views/tool/gen/importTable.vue

2-1 导入按钮:

上面 导入按钮组件 ,在index页面中

按钮逻辑:

       1-点击导入按钮,调用弹框页面show方法

        2-show 展示导入选表页面,渲染所有表列表

//0-引入导入页面组件
import importTable from "./importTable";
export default {
  name: "Gen",
  components: { importTable },



//1-点击导入按钮,触发 openImportTable方法
  <el-button
          type="info"
          plain
          icon="el-icon-upload"
          size="mini"
          @click="openImportTable"
          v-hasPermi="['tool:gen:import']"
        >导入</el-button>


//2-js方法:openImportTable
   /** 打开导入表弹窗 调用了import组件里面的show方法 */
    openImportTable() {
      this.$refs.import.show();
    },



//3-import组件中show方法:调用后台接口: /db/list 查询数据,并展示弹框页面
 show() {
      this.getList();
      this.visible = true;
    },
 
    // 查询表数据
    getList() {
      listDbTable(this.queryParams).then(res => {
        if (res.code === 200) {
          this.dbTableList = res.rows;
          this.total = res.total;
        }
      });
    },

后台查询列表中

根据  <if>条件 判断数据库类型,执行对应sql,查询数据库所有表

<if test="@com.ruoyi.common.helper.DataBaseHelper@isMySql()">:判断是myql

<if test="@com.ruoyi.common.helper.DataBaseHelper@isOracle()">:判断oracle查询对应库博

<select id="selectPageDbTableList" resultMap="GenTableResult">
        <if test="@com.ruoyi.common.helper.DataBaseHelper@isMySql()">
            select table_name, table_comment, create_time, update_time
            from information_schema.tables
            where table_schema = (select database())
            AND table_name NOT LIKE 'xxl_job_%' AND table_name NOT LIKE 'gen_%'
            AND table_name NOT IN (select table_name from gen_table)
            <if test="genTable.tableName != null and genTable.tableName != ''">
                AND lower(table_name) like lower(concat('%', #{genTable.tableName}, '%'))
            </if>
            <if test="genTable.tableComment != null and genTable.tableComment != ''">
                AND lower(table_comment) like lower(concat('%', #{genTable.tableComment}, '%'))
            </if>
            order by create_time desc
        </if>
        <if test="@com.ruoyi.common.helper.DataBaseHelper@isOracle()">
            select lower(dt.table_name) as table_name, dtc.comments as table_comment, uo.created as create_time, uo
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

syfjava

请博主喝杯蜜雪冰城

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值