package com.xjrsoft.xjrsoftboot;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import org.junit.jupiter.api.Test;

import java.util.Arrays;

public class MysqlGeneratorTest {

    /**
     * 数据源配置
     */
    private static final DataSourceConfig.Builder DATA_SOURCE_CONFIG = new DataSourceConfig.Builder(
            "jdbc:mysql://8.142.26.206:3306/tl?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true", "root", "Zwr~-f6H,u6QE^]C-AD_");

    @Test
    public void MysqlGeneratorTest() {
        FastAutoGenerator.create(DATA_SOURCE_CONFIG)
                .globalConfig(builder -> {
                    builder.outputDir("/Users/fanxp/Documents/code/java/demo1/demo1/mybatis02/src/main/java") //设置输出路径：项目的 java 目录下【System.getProperty("user.dir")意思是获取到项目所在的绝对路径】
                            .commentDate("yyyy-MM-dd hh:mm:ss")   //注释日期
                            .dateType(DateType.ONLY_DATE)   //定义生成的实体类中日期的类型 TIME_PACK=LocalDateTime;ONLY_DATE=Date;
                            .enableSwagger()   //开启 swagger 模式
                            .disableOpenDir();
                })
                .packageConfig(builder -> {
                    builder.moduleName("courseTable")   //设置模块包名
                            .parent("com.xjrsoft.module"); //设置报名
                })
                .strategyConfig(builder -> {
                    builder.addInclude(Arrays.asList("course_table", "class_time"));// 设置需要生成的数据表名
                })
                .execute();
    }
}
