SpringBoot集成mybatis-plus生成实体类

1.pom.xml添加依赖

SpringBoot集成mybatis-plus生成实体类_第1张图片

2.配置mybatis-plus,在application.yml中添加:

SpringBoot集成mybatis-plus生成实体类_第2张图片

配置数据库连接:

SpringBoot集成mybatis-plus生成实体类_第3张图片

3.在com/dtest02/demo/system/config下添加MyBatisPlusConfig.java

SpringBoot集成mybatis-plus生成实体类_第4张图片

4.启动文件application.java中配置@MapperScan

SpringBoot集成mybatis-plus生成实体类_第5张图片

5.在com/dtest02/demo/utils下配置代码生成器MpGenerator

package com.dtest02.demo.utils;

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;

/**
 *
 * @author d
 * @ClassName: CodeGeneration
 * @Description: 代码生成器
 */
public class MpGenerator {

    /**
     *
     * @Title: main
     * @Description: 生成
     */
    public static void main(String[] args) {
        AutoGenerator mpg = new AutoGenerator();

        // 全局配置
        GlobalConfig gc = new GlobalConfig();
        //输出文件路径
        gc.setOutputDir("F://java//javamodel//test02");
        gc.setFileOverride(true);
        // 不需要ActiveRecord特性的请改为false
        gc.setActiveRecord(false);
        // XML 二级缓存
        gc.setEnableCache(false);
        // XML ResultMap
        gc.setBaseResultMap(true);
        // XML columnList
        gc.setBaseColumnList(false);
        gc.setAuthor("dps");

        // 自定义文件命名,注意 %s 会自动填充表实体属性!
        gc.setControllerName("%sController");
        gc.setServiceName("%sService");
        gc.setServiceImplName("%sServiceImpl");
        gc.setMapperName("%sMapper");
        gc.setXmlName("%sMapper");
        mpg.setGlobalConfig(gc);

        // 数据源配置
        DataSourceConfig dsc = new DataSourceConfig();
        dsc.setDbType(DbType.MYSQL);
        dsc.setDriverName("com.mysql.jdbc.Driver");
        dsc.setUsername("root");
        dsc.setPassword("123456");
        dsc.setUrl("jdbc:mysql://192.168.19.101:3306/course?useUnicodle=true&characterEncoding=utf8&useSSL=false&serverTimezone=UTC");
        mpg.setDataSource(dsc);

        // 策略配置
        StrategyConfig strategy = new StrategyConfig();
        // 表名生成策略
        strategy.setNaming(NamingStrategy.underline_to_camel);
        // 需要生成的表
        strategy.setInclude("admin_log","comment","courseinfo","courses","coursetype","indeximg","log","mycourse","mylike","news","note","privilege","role","school","talk","user","webinfo");
        strategy.setSuperServiceClass(null);
        strategy.setSuperServiceImplClass(null);
        strategy.setSuperMapperClass(null);

        mpg.setStrategy(strategy);

        // 包配置
        PackageConfig pc = new PackageConfig();
        pc.setParent("com.dtest02.demo");
        pc.setController("controller");
        pc.setService("service");
        pc.setServiceImpl("service.impl");
        pc.setMapper("dao");
        pc.setEntity("model");
        pc.setXml("mapper");
        mpg.setPackageInfo(pc);

        // 执行生成
        mpg.execute();

    }
}

启动主函数,可以生成实体类:

SpringBoot集成mybatis-plus生成实体类_第6张图片

 

你可能感兴趣的:(SpringBoot集成mybatis-plus生成实体类)