首页>代码>基于spring boot+layui+redis+activiti+Apache Shiro整合开发网站权限管理系统>/kvf-admin-activiti/kvf-admin-activiti/src/main/java/com/kalvin/kvf/common/CodeGenerator.java
package com.kalvin.kvf.common;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.*;
import com.baomidou.mybatisplus.generator.config.converts.MySqlTypeConvert;
import com.baomidou.mybatisplus.generator.config.rules.DbColumnType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;


/**
 * 【作用】代码生成器<br>
 * 【说明】(无)
 * @author Kalvin
 * @Date 2019/4/16 15:11
 */
public class CodeGenerator {

    private static String packageName = "com.kalvin.kvf"; // 生成的包名
    private static String[] tableNames = {"sys_log"};   // 表名
    private static String tablePrefix = "sys_";    // 配置了会自动去掉表名的前缀
    private static boolean serviceNameStartWithI = true;  //user -> UserService, 设置成true: user -> IUserService
    private static String author = "Kalvin";    // 作者
    private static String outputDir = "D://genCode";   // 代码生成的路径目录
    private static String dbUrl = "jdbc:mysql://localhost:3306/activiti_k?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false&tinyInt1isBit=false&serverTimezone=GMT%2B8";
    private static String dbUsername = "root";
    private static String dbPassword = "root";

    public static void main(String[] args) {
        generateByTables(serviceNameStartWithI, packageName, tableNames);
    }

    private static void generateByTables(boolean serviceNameStartWithI, String packageName, String... tableNames) {
        GlobalConfig config = new GlobalConfig();
        DataSourceConfig dataSourceConfig = new DataSourceConfig();
        dataSourceConfig.setDbType(DbType.MYSQL).setUrl(dbUrl).setUsername(dbUsername).setPassword(dbPassword)
                .setDriverName("com.mysql.jdbc.Driver").setTypeConvert((globalConfig, s) -> {
            if (s.contains("tinyint(1)")) { // 自定义数据库表字段类型转换
                return DbColumnType.INTEGER;
            }
            return new MySqlTypeConvert().processTypeConvert(globalConfig, s);
        });
        StrategyConfig strategyConfig = new StrategyConfig();
        strategyConfig
                .setCapitalMode(true)
                .setEntityLombokModel(true)
//                .setDbColumnUnderline(true)
                .setTablePrefix(tablePrefix)
                .setNaming(NamingStrategy.underline_to_camel)
                .setInclude(tableNames)//修改替换成你需要的表名,多个表名传数组
                .setRestControllerStyle(true)
                .setSuperEntityClass("com.kalvin.kvf.common.entity.BaseEntity")
                .setSuperControllerClass("com.kalvin.kvf.common.controller.BaseController");

        config.setActiveRecord(false)
                .setAuthor(author)
                .setOutputDir(outputDir)
                .setFileOverride(true)
                .setEnableCache(false)
                .setBaseResultMap(true)
                .setBaseColumnList(true);
        TemplateConfig tc = new TemplateConfig();
        if (!serviceNameStartWithI) {
            config.setServiceName("%sService");
            config.setMapperName("%sMapper");
        }
        new AutoGenerator().setGlobalConfig(config)
                .setTemplate(tc)
                .setDataSource(dataSourceConfig)
                .setStrategy(strategyConfig)
                .setPackageInfo(
                        new PackageConfig()
                                .setParent(packageName)
                                .setEntity("entity.sys")
                                .setMapper("mapper.sys")
                                .setController("controller.sys")
                                .setService("service.sys")
                                .setServiceImpl("service.sys")
                                .setXml("xml.sys")
                ).execute();
    }
}
最近下载更多
educationAAA  LV11 2024年11月4日
TY0165  LV20 2024年6月21日
简约时尚  LV13 2024年1月16日
skipple3  LV39 2023年10月26日
x1048446262  LV2 2023年8月30日
yoyoch1  LV1 2023年8月28日
3334004690  LV11 2023年8月15日
zhy1989wz  LV7 2023年7月6日
微信网友_6482083022819328  LV14 2023年6月3日
oclocl  LV1 2023年4月12日
最近浏览更多
Solowen 4月16日
暂无贡献等级
citybird  LV4 2024年11月20日
sunlzh888888  LV29 2024年9月20日
李朝磊  LV18 2024年7月3日
educationAAA  LV11 2024年6月23日
TY0165  LV20 2024年6月21日
颜菜菜  LV2 2024年6月19日
xiaozhi丶  LV15 2024年3月24日
Gin19960217  LV4 2024年3月5日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友