微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

mybatis plus 基础代码生成器

1, 复制代码 2 导入依赖 3运行main方法 ok
public class CodeGenerator {

    //数据库路径
    private static String url = "jdbc:MysqL://192.176.17.7:3306/plus_db?useUnicode=true&useSSL=false&characterEncoding=utf8&serverTimezone=GMT%2B8";
    private static String username = "root";
    private static String password = "root";
    private static String packagePath = "com.qyy.plus"; //包路径
    private static String author = "qyy"; //作者
    private static String prefix = ""; //前缀
    private static String projectPath = "D:\\mybatisPlus\\workspace\\qyy_db\\plus"; //项目的路径,在下面自动拼接了 /src/main/java
    private static String[] tables = {"tool_user"};//生成的表


    public static void main(String[] args) {
        // 代码生成器
        AutoGenerator mpg = new AutoGenerator();

        // 全局配置
        GlobalConfig gc = new GlobalConfig();
        //String projectPath = "D:\\ideaWork\\iot-coldchain";
        gc.setoutputDir(projectPath + "/src/main/java");
        gc.setAuthor(author);
        gc.setopen(false);// 生成后是否打开资源管理器
        gc.setFileOverride(true);//文件是否覆盖
        gc.setServiceName("%sService");//去掉Service接口的首字母I
        gc.setIdType(IdType.AUTO);// 主键策略
        gc.setDateType(DateType.ONLY_DATE);// 日期类型
        gc.setSwagger2(false); // 实体属性 Swagger2 注解
        mpg.setGlobalConfig(gc);

        // 数据源配置
        DataSourceConfig dsc = new DataSourceConfig();
        dsc.setUrl(url);
        // dsc.setSchemaName("public");
        dsc.setDriverName("com.MysqL.cj.jdbc.Driver");
        dsc.setUsername(username);
        dsc.setPassword(password);
        dsc.setDbType(DbType.MysqL);
        mpg.setDataSource(dsc);

        // 包配置
        PackageConfig pc = new PackageConfig();
        // 主模块,会自动多创建一层包
        //pc.setModuleName("user");
        pc.setParent(packagePath);
        pc.setController("controller");
        pc.setService("service");
        pc.setEntity("entity");
        pc.setMapper("mapper");
        mpg.setPackageInfo(pc);


        // 策略配置
        StrategyConfig strategy = new StrategyConfig();
        strategy.setInclude(tables);
        strategy.setNaming(NamingStrategy.underline_to_camel);//表和实体类的命名规则
        strategy.setTablePrefix(prefix);
        //strategy.setTablePrefix(pc.getModuleName()+"_");
        strategy.setColumnNaming(NamingStrategy.underline_to_camel);//字段映射规则
        strategy.setEntityLombokModel(true);
        strategy.setRestControllerStyle(true); //restfulapi风格
        strategy.setControllerMappingHyphenStyle(true);//url中驼峰转连字符
        mpg.setStrategy(strategy);


        mpg.execute();
    }

2 依赖包

    <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-generator</artifactId>
            <version>3.3.2</version>
    </dependency>
	<dependency>
            <groupId>org.apache.veLocity</groupId>
            <artifactId>veLocity-engine-core</artifactId>
            <version>2.0</version>
    </dependency>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐