mybatis-plus怎么自动生成类

本篇内容介绍了“mybatis-plus怎么自动生成类”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

为尼木等地区用户提供了全套网页设计制作服务,及尼木网站建设行业解决方案。主营业务为网站建设、网站设计、尼木网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!

目录

pom 依赖
执行sql
demo

pom.xml

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus-generator</artifactId>
    <version>3.1.2</version>
</dependency>

<dependency>
    <groupId>MySQL</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>8.0.11</version>
</dependency>

<dependency>
    <groupId>org.apache.velocity</groupId>
    <artifactId>velocity-engine-core</artifactId>
    <version>2.0</version>
</dependency>
<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <version>1.18.8</version>
</dependency>

执行sql

CREATE TABLE if not exists `tbl_product_category` (  
  `id` int(11) NOT NULL AUTO_INCREMENT,  
  `category_pic_code` varchar(100) NOT NULL comment '图片地址id',
  `name` varchar(255) NOT NULL comment '产品类别名字', 
  `status` bit(1) NOT NULL  default 1 comment '0 无效 1有效',
  `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)  
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 comment='产品类别信息';

执行代码

public static void main(String[] args) {

        String projectPath = System.getProperty("user.dir");
        String outputDir = projectPath + "/src/main/java"; //生成文件输出目录
        String author = "duanlsh"; //注释作者
        String entity = "ProductCategory"; //生成文件实体名称
        String entityPrefix = "tbl_"; //前缀
        String[] tableName = "tbl_product_category".split(","); //表名多个以 , 分割
        String packageName = "com.apple"; //生成文件的 包名

        //数据库
        String dbUrl = "jdbc:mysql://localhost:3306/grainfull?characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC";
        DataSourceConfig dataSourceConfig = new DataSourceConfig();
        dataSourceConfig.setDbType(DbType.MYSQL)
                .setUrl(dbUrl)
                .setUsername("root")
                .setPassword("root")
                .setDriverName("com.mysql.cj.jdbc.Driver");


        GlobalConfig config = new GlobalConfig();
        config.setAuthor(author);
        config.setOutputDir(outputDir);
        config.setFileOverride(true);
        config.setOpen(false); //文件生成完是否打开目录
        config.setEntityName("%sModel");//实体类添加Model
        config.setServiceName("%sService");
        config.setControllerName("%sController");
        config.setServiceImplName("%sServiceImpl");
        config.setMapperName("%sMapper");
        config.setXmlName("%sMapper");

        StrategyConfig strategyConfig = new StrategyConfig();
        strategyConfig
                .setCapitalMode(true)
                .setEntityLombokModel(true) //设置是否使用 lombook
//                .setDbColumnUnderline(true)
                .setNaming(NamingStrategy.underline_to_camel)
                .setColumnNaming(NamingStrategy.underline_to_camel)
                .setRestControllerStyle(true)
                .setControllerMappingHyphenStyle(true)
//                .setSuperEntityClass("com.baomidou.mybatisplus.extension.service.impl.ServiceImpl")
//                .setSuperMapperClass("com.baomidou.mybatisplus.core.mapper.BaseMapper")
                .setInclude(tableName)//修改替换成你需要的表名,多个表名传数组
                .setTablePrefix(entityPrefix)
                ;

        InjectionConfig cfg = new InjectionConfig() {
            @Override
            public void initMap() {
                //do nothing
            }
        };

        PackageConfig packageConfig = new PackageConfig();
//        packageConfig.setModuleName("ProductCategory"); //在parent包下面添加的包名 eg: com.apple.ProductCategory
        packageConfig.setParent(packageName);
        packageConfig.setController("controller");
        packageConfig.setService("service");
        packageConfig.setServiceImpl("service.impl");
        packageConfig.setEntity("model");


//        TemplateConfig templateConfig  = new TemplateConfig();
//        templateConfig.setEntity("/templates/entity2.java");
//        templateConfig.setXml(null);

        AutoGenerator mpg = new AutoGenerator();
//        mpg.setTemplate(templateConfig);
        mpg.setGlobalConfig(config);
        mpg.setDataSource(dataSourceConfig);
        mpg.setStrategy(strategyConfig);
        mpg.setCfg(cfg);
        mpg.setPackageInfo(packageConfig);
        mpg.execute();
    }

“mybatis-plus怎么自动生成类”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注创新互联网站,小编将为大家输出更多高质量的实用文章!

网页题目:mybatis-plus怎么自动生成类
当前地址:https://www.cdcxhl.com/article0/jpsjoo.html

成都网站建设公司_创新互联,为您提供网站导航品牌网站制作企业建站外贸建站域名注册ChatGPT

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

成都网站建设公司