• MyBatis 自动代码生成器


    相关实现

    package com.zyh.domain.mainCode;
    import com.baomidou.mybatisplus.generator.AutoGenerator;
    import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
    import com.baomidou.mybatisplus.generator.config.GlobalConfig;
    import com.baomidou.mybatisplus.generator.config.PackageConfig;
    import com.baomidou.mybatisplus.generator.config.StrategyConfig;
    import com.baomidou.mybatisplus.generator.config.rules.DbType;
    import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
    
    /**
     * 代码自动生成器 了解下
     *
     * POM.XML 文件添加依赖
      <!-- Mybatis-Plus  自动生成实体类-->
            <dependency>
                <groupId>com.baomidou</groupId>
                <artifactId>mybatis-plus</artifactId>
                <version>2.0.6</version>
            </dependency>
            <dependency>
                <groupId>org.apache.velocity</groupId>
                <artifactId>velocity</artifactId>
                <version>1.7</version>
            </dependency>
     *
     * Created by ehomeud on 2017/4/26.
     */
    
    public class Test{
        public static void main(String[] args) throws InterruptedException {
            AutoGenerator mpg = new AutoGenerator();
    
            // 全局配置
            GlobalConfig gc = new GlobalConfig();
            gc.setOutputDir("E://");// 项目文件输出地址
            gc.setFileOverride(true);
            gc.setActiveRecord(true);
            gc.setEnableCache(true);// XML 二级缓存
            gc.setBaseResultMap(true);// XML ResultMap
            gc.setBaseColumnList(true);// XML columList
            gc.setAuthor("ZYH");
    
            // 自定义文件命名,注意 %s 会自动填充表实体属性!
             gc.setMapperName("%sDao");
             gc.setXmlName("%sMapper");
             gc.setServiceName("%sService");
             gc.setServiceImplName("%sServiceImap");
             gc.setControllerName("%sController");
            mpg.setGlobalConfig(gc);
    
            // 数据源配置
            DataSourceConfig dsc = new DataSourceConfig();
            dsc.setDbType(DbType.MYSQL);
            /*dsc.setTypeConvert(new MySqlTypeConvert(){
                // 自定义数据库表字段类型转换【可选】
                @Override
                public DbColumnType processTypeConvert(String fieldType) {
                    System.out.println("转换类型:" + fieldType);
                    return super.processTypeConvert(fieldType);
                }
            });*/
    
            // 数据库登录相关配置
            dsc.setDriverName("com.mysql.jdbc.Driver");
            dsc.setUrl("jdbc:mysql://192.168.12.244:3310/test?useUnicode=true&amp;characterEncoding=UTF-8&amp;generateSimpleParameterMetadata=true");
            dsc.setUsername("root");
            dsc.setPassword("1101399");
            mpg.setDataSource(dsc);
    
            // 策略配置
            StrategyConfig strategy = new StrategyConfig();
            // strategy.setCapitalMode(true);// 全局大写命名 ORACLE 注意
            // strategy.setTablePrefix(new String[] { "tlog_", "tsys_" });// 此处可以修改为您的表前缀
            strategy.setNaming(NamingStrategy.underline_to_camel);// 表名生成策略
            // strategy.setInclude(new String[] { "user" }); // 需要生成的表
            // strategy.setExclude(new String[]{"test"}); // 排除生成的表
            mpg.setStrategy(strategy);
    
            // 包配置
            PackageConfig pc = new PackageConfig();
            pc.setParent("com.zyh");
            pc.setModuleName("test");
            mpg.setPackageInfo(pc);
    
            // 执行生成
            mpg.execute();
        }
    
    }

     通过MyBatis封装的插件实现对数据库表的读取,通过对数据表以及数据字段的处理生成一个又一个对应的entity文件类、Mapper包、server包、controller包等等。

    其他MyBatis代码生成器使用方案:

    利用mybatis-generator自动生成代码

    Mybatis-Plus代码生成器

    Maven插件之mybatis-generator(mybatis自动生成实体代码的插件)

    SSM框架----使用Generator自动生成代码(亲测可用且效果比较好)

     

    痛苦预示着超脱
  • 相关阅读:
    代码中引用res里的颜色、图片
    time.setToNow() 取当前时间,月份有误
    adb报错:The connection to adb is down, and a severe&nbs
    安卓下拉刷新、上拉加载数据显示
    4、安卓数据存储——sqlite
    3、安卓数据存储——缓存、内存管理
    2、安卓数据存储——本地文件
    1、安卓数据存储机制——sharedPreference
    一个异步任务接收两个url下载两个图片
    adb报错:The connection to adb is down, and a severe&nbs
  • 原文地址:https://www.cnblogs.com/supperlhg/p/8757238.html
Copyright © 2020-2023  润新知