zoukankan      html  css  js  c++  java
  • mybatis-plus 代码生成器

        <dependency>
                <groupId>com.baomidou</groupId>
                <artifactId>mybatis-plus-boot-starter</artifactId>
                <version>3.0.5</version>
            </dependency>
    
            <!-- mybatis-plus 代码生成器需要的依赖 -->
            <dependency>
                <groupId>org.apache.velocity</groupId>
                <artifactId>velocity-engine-core</artifactId>
                <version>2.0</version>
            </dependency>
    public class PlusGenerator {
        
        public static final String projectPath = "D:\Users\Administrator\eclipse-workspace\mybatisplus\src\main\java\";
    
        public static void main(String[] args) {
            generator();
        }
    
        public static void generator() {
            // 代码生成器
            AutoGenerator ag = new AutoGenerator();
    
            // 全局配置
            GlobalConfig gc = new GlobalConfig();
            gc.setAuthor("zhangsan");
            gc.setOpen(false);
            gc.setOutputDir(projectPath);
            gc.setBaseResultMap(true);                //xml resultmap
            // 自定义文件命名,注意 %s 会自动填充表实体属性!
            gc.setControllerName("%sController");
            gc.setServiceName("%sService");
            gc.setServiceImplName("%sServiceImpl");
            gc.setMapperName("%sMapper");
            gc.setXmlName("%sMapper");
            ag.setGlobalConfig(gc);
    
            // 配置数据源
            DataSourceConfig dsc = new DataSourceConfig();
            dsc.setDbType(DbType.MYSQL);
            dsc.setDriverName("com.mysql.cj.jdbc.Driver");
            dsc.setUsername("root");
            dsc.setPassword("123456");
            dsc.setUrl("jdbc:mysql://localhost:3306/dbtest?serverTimezone=GMT%2B8");
            ag.setDataSource(dsc);
    
            // 包配置
            PackageConfig pc = new PackageConfig();
            pc.setParent("com.example.demo");
            pc.setController("controller");
            pc.setService("service");
            pc.setServiceImpl("serviceImpl");
            pc.setMapper("mapper");
            pc.setEntity("entity");
            pc.setXml("xml");
            ag.setPackageInfo(pc);
    
            //策略配置
            StrategyConfig strategy = new StrategyConfig();
            //strategy.setTablePrefix(new String[] { "tb_" });// 此处可以修改为您的表前缀
            strategy.setNaming(NamingStrategy.underline_to_camel);// 表名生成策略
            strategy.setInclude(new String[] {"sc","course","teacher","student" }); // 需要生成的表
    
            strategy.setSuperServiceClass(null);
            strategy.setSuperServiceImplClass(null);
            strategy.setSuperMapperClass(null);
            strategy.setRestControllerStyle(true);
    
            ag.setStrategy(strategy);
    
            ag.execute();
            
        }
    }
    温故而知新
  • 相关阅读:
    vue.js环境配置步骤及npm run dev报错解决方案
    消息处理之performSelector
    iOS开发网络篇—发送GET和POST请求(使用NSURLSession)
    iOS手机号正则表达式并实现344格式 (正则的另一种实现方式)
    IOS开发——正则表达式验证手机号、密码
    iOS网络请求之---GET和POST
    CLLocation
    ios本地文件内容读取,.json .plist 文件读写
    UITableViewCell的4种样式
    iOS开发通过代码方式使用AutoLayout (NSLayoutConstraint + Masonry)
  • 原文地址:https://www.cnblogs.com/Uzai/p/10236051.html
Copyright © 2011-2022 走看看