com.baomidou.mybatisplus.generator.config.rules.DateType Java Examples

The following examples show how to use com.baomidou.mybatisplus.generator.config.rules.DateType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CodeGenerator.java    From My-Blog-layui with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
        // 代码生成器
        AutoGenerator mpg = new AutoGenerator();

        // 全局配置
        GlobalConfig gc = new GlobalConfig();
        // 当前工程路径
        String projectPath = System.getProperty("user.dir");
        gc.setOutputDir(projectPath + outPutDir);
        gc.setDateType(DateType.ONLY_DATE);
        gc.setAuthor("zhulin");
        gc.setOpen(false);
        gc.setBaseResultMap(true);
        gc.setBaseColumnList(true);
        // 覆盖生成的文件
        gc.setFileOverride(true);
        gc.setServiceName("%sService");
        mpg.setGlobalConfig(gc);

        // 数据源配置
        DataSourceConfig dsc = new DataSourceConfig();
        dsc.setUrl(dataUrl);
        dsc.setDriverName(driverName);
        dsc.setUsername(dataName);
        dsc.setPassword(dataPwd);
        mpg.setDataSource(dsc);

        // 包配置
        PackageConfig pc = new PackageConfig();
        pc.setParent(parentPackage)
                .setMapper(mapperName)
                .setEntity(pojoName)
                .setService(serviceName)
                .setController(controllerName)
                .setServiceImpl(implName)
                .setXml(xmlName);
        mpg.setPackageInfo(pc);

/*        // 自定义配置
        InjectionConfig cfg = new InjectionConfig() {
            @Override
            public void initMap() {
                // to do nothing
            }
        };
        // 自定义输出配置
        List<FileOutConfig> focList = new ArrayList<>();
        focList.add(new FileOutConfig() {
            @Override
            public String outputFile(TableInfo tableInfo) {
                // 自定义输出文件名 , 如果你 Entity 设置了前后缀、此处注意 xml 的名称会跟着发生变化!!
                return projectPath + "/src/main/resources/mapping/"
                        + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML;
            }
        });
        cfg.setFileOutConfigList(focList);
        mpg.setCfg(cfg);*/


        // 策略配置
        StrategyConfig strategy = new StrategyConfig();
        strategy.setNaming(NamingStrategy.underline_to_camel);
        strategy.setColumnNaming(NamingStrategy.underline_to_camel);
        strategy.setEntityTableFieldAnnotationEnable(true);
        strategy.setEntityLombokModel(true);
        strategy.setInclude(scanner("表名,多个英文逗号分割").split(","));
        //默认生成全部
/*        strategy.setExclude(null);*/
        strategy.setControllerMappingHyphenStyle(true);
        mpg.setStrategy(strategy);
        mpg.execute();
    }
 
Example #2
Source File: SpringBootPlusGenerator.java    From spring-boot-plus with Apache License 2.0 4 votes vote down vote up
/**
 * 生成代码
 * @param args
 */
public static void main(String[] args) {
    GeneratorProperties generatorProperties = new GeneratorProperties();

    // 设置基本信息
    generatorProperties
            .setMavenModuleName("example")
            .setParentPackage("com.example")
            .setModuleName("foobar")
            .setAuthor("geekidea")
            .setFileOverride(true);

    // 设置表信息
    generatorProperties.addTable("foo_bar","id");
    // 设置表前缀
    // generatorProperties.setTablePrefix(Arrays.asList("tb_"));

    // 数据源配置
    generatorProperties.getDataSourceConfig()
            .setDbType(DbType.MYSQL)
            .setUsername("root")
            .setPassword("root")
            .setDriverName("com.mysql.jdbc.Driver")
            .setUrl("jdbc:mysql://localhost:3306/spring_boot_plus?useUnicode=true&characterEncoding=UTF-8&useSSL=false");

    // 生成配置
    generatorProperties.getGeneratorConfig()
            .setGeneratorStrategy(GeneratorStrategy.SINGLE)
            .setGeneratorEntity(true)
            .setGeneratorController(true)
            .setGeneratorService(true)
            .setGeneratorServiceImpl(true)
            .setGeneratorMapper(true)
            .setGeneratorMapperXml(true)
            .setGeneratorPageParam(true)
            .setGeneratorQueryVo(true)
            .setRequiresPermissions(false)
            .setPageListOrder(true)
            .setParamValidation(true)
            .setSwaggerTags(true)
            .setOperationLog(true);

    // 全局配置
    generatorProperties.getMybatisPlusGeneratorConfig().getGlobalConfig()
            .setOpen(true)
            .setSwagger2(true)
            .setIdType(IdType.AUTO)
            .setDateType(DateType.ONLY_DATE);

    // 策略配置
    generatorProperties.getMybatisPlusGeneratorConfig().getStrategyConfig()
            .setNaming(NamingStrategy.underline_to_camel)
            .setColumnNaming(NamingStrategy.underline_to_camel)
            .setEntityLombokModel(true)
            .setRestControllerStyle(true)
            .setControllerMappingHyphenStyle(true)
            .setVersionFieldName(GeneratorConstant.VERSION)
            .setLogicDeleteFieldName(GeneratorConstant.DELETED);

    // 生成代码
    CodeGenerator codeGenerator = new CodeGenerator();
    codeGenerator.generator(generatorProperties);

}
 
Example #3
Source File: AdminMpGenerator.java    From charging_pile_cloud with MIT License 4 votes vote down vote up
public static void main(String[] args) {
        // 代码生成器
        AutoGenerator mpg = new AutoGenerator();

        // 全局配置
        GlobalConfig gc = new GlobalConfig();
        String projectPath = System.getProperty("user.dir");
        gc.setOutputDir("D:\\code");
        gc.setAuthor("kongling");
        gc.setOpen(true);
        gc.setSwagger2(false);
        gc.setDateType(DateType.ONLY_DATE);
        gc.setBaseResultMap(true);
        gc.setBaseColumnList(true);
        gc.setSwagger2(true);
        gc.setActiveRecord(true);
        mpg.setGlobalConfig(gc);

        // 数据源配置
        DataSourceConfig dsc = new DataSourceConfig();
        dsc.setUrl("jdbc:mysql://127.0.0.1:3306/charging_pile?serverTimezone=UTC");
        // dsc.setSchemaName("public");
        dsc.setDriverName("com.mysql.jdbc.Driver");
        dsc.setUsername("root");
        dsc.setPassword("root");
        mpg.setDataSource(dsc);

        // 包配置
        PackageConfig pc = new PackageConfig();
        //pc.setModuleName(scanner("模块名"));
        pc.setParent(scanner("包名,例如:com.sskj.admin"));
        mpg.setPackageInfo(pc);
        // 自定义配置
        InjectionConfig cfg = new InjectionConfig() {
            @Override
            public void initMap() {
                // to do nothing
            }
        };

        // 如果模板引擎是 freemarker
        String templatePath = "/templates/mapper.xml";
        // 如果模板引擎是 velocity
        // String templatePath = "/templates/mapper.xml.vm";

        // 自定义输出配置
        List<FileOutConfig> focList = new ArrayList<>();
        // 自定义配置会被优先输出
/*
		focList.add(new FileOutConfig(templatePath) {
			@Override
			public String outputFile(TableInfo tableInfo) {
				// 自定义输出文件名 , 如果你 Entity 设置了前后缀、此处注意 xml 的名称会跟着发生变化!!
				return projectPath + "/src/main/resources/mapper/" + pc.getModuleName()
						+ "/" + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML;
			}
		});
*/

        cfg.setFileOutConfigList(focList);
        mpg.setCfg(cfg);

        // 配置模板
        TemplateConfig templateConfig = new TemplateConfig();

        // 配置自定义输出模板
        //指定自定义模板路径,注意不要带上.ftl/.vm, 会根据使用的模板引擎自动识别
        // templateConfig.setEntity("templates/entity2.java");
        // templateConfig.setService();
        // templateConfig.setController();

        templateConfig.setXml(templatePath);
        mpg.setTemplate(templateConfig);

        // 策略配置
        StrategyConfig strategy = new StrategyConfig();
        strategy.setNaming(NamingStrategy.underline_to_camel);
        //	strategy.setSuperEntityClass("com.baomidou.ant.common.BaseEntity");
        //RestController
        strategy.setRestControllerStyle(false);
        //strategy.setSuperControllerClass("com.baomidou.ant.common.BaseController");
        strategy.setInclude(scanner("表名"));
      //  strategy.setSuperEntityColumns("id");
        strategy.setControllerMappingHyphenStyle(false);
        strategy.setTablePrefix(pc.getModuleName() + "_");
        strategy.setEntityTableFieldAnnotationEnable(true);
        strategy.setEntityLombokModel(true);
        /**
         * boolean 是否一处前缀is
         */
        strategy. setEntityBooleanColumnRemoveIsPrefix(false);
        mpg.setStrategy(strategy);
        mpg.setTemplateEngine(new FreemarkerTemplateEngine());
        mpg.execute();
    }
 
Example #4
Source File: MBPlusTest.java    From Resource with GNU General Public License v3.0 4 votes vote down vote up
public static void main(String[] args)
{
    AutoGenerator ag = new AutoGenerator();

    // 全局配置
    GlobalConfig gc = new GlobalConfig();
    //gc.setOutputDir("D:\\workspace\\SpringBoot\\src\\main\\java");//将代码生成在项目中
    gc.setOutputDir(System.getProperty("user.dir") + "/src/main/java");//将代码生成在指定目录中
    gc.setFileOverride(true);
    gc.setActiveRecord(false);  // 不需要ActiveRecord特性的请改为false
    gc.setEnableCache(false);   // XML 二级缓存
    gc.setBaseResultMap(true);  // XML ResultMap
    gc.setBaseColumnList(false);// XML columnList
    gc.setAuthor("zsm");        // 作者
    gc.setDateType(DateType.ONLY_DATE);//只生成java.util.Date类型时间格式

    // 自定义文件命名,注意 %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.jdbc.Driver");
    dsc.setUsername("root");
    dsc.setPassword("123456");
    dsc.setUrl("jdbc:mysql://127.0.0.1:3306/test_db?characterEncoding=utf-8");
    ag.setDataSource(dsc);

    // 策略配置
    StrategyConfig strategy = new StrategyConfig();
    // strategy.setCapitalMode(true);   // 全局大写命名 ORACLE 注意
    strategy.setTablePrefix(new String[] {"tb_"});       // 此处可以修改为您的表前缀
    strategy.setNaming(NamingStrategy.underline_to_camel);  // 表名生成策略
    strategy.setInclude(new String[] {"tb_user", "tb_order"}); // 需要生成的表
    // strategy.setExclude(new String[]{"tb_test"});   // 排除生成的表

    strategy.setSuperServiceClass(null);        // 自定义 service 父类
    strategy.setSuperServiceImplClass(null);
    strategy.setSuperMapperClass(null);
    // 自定义实体父类
    //strategy.setSuperEntityClass(com.zsm.sb.entity.BaseEntity);
    // 自定义实体,公共字段
    //strategy.setSuperEntityColumns(new String[] { "test_id", "userId" });
    // 自定义 mapper 父类
    // strategy.setSuperMapperClass("com.zsm.sb.mapper.BaseMapper");
    // 自定义 service 父类
    // strategy.setSuperServiceClass("com.zsm.sb.service.BaseService");
    // 自定义 service 实现类父类
    // strategy.setSuperServiceImplClass("com.zsm.sb.service.BaseServiceImpl");
    // 自定义 controller 父类
    // strategy.setSuperControllerClass("com.zsm.sb.controller.BaseController");
    // 实体是否生成字段常量(默认 false)
    // public static final String ID = "userId";
    // strategy.setEntityColumnConstant(true);
    // 实体是否为构建者模型(默认 false)
    // public User setName(String name) {this.name = name; return this;}
    //strategy.setEntityBuilderModel(true);
    ag.setStrategy(strategy);

    // 生成代码包名配置
    PackageConfig pc = new PackageConfig();
    pc.setParent("com.zsm.sb");
    pc.setController("controller");
    pc.setService("service");
    pc.setServiceImpl("service.impl");
    pc.setMapper("dao");
    pc.setEntity("model");
    pc.setXml("mapper");
    ag.setPackageInfo(pc);

    // 自定义 xxList.jsp 生成
    List<FileOutConfig> focList = new ArrayList<FileOutConfig>();
    // focList.add(new FileOutConfig("/template/list.jsp.vm") {
    // @Override
    // public String outputFile(TableInfo tableInfo) {
    // // 自定义输入文件名称
    // return "D://my_" + tableInfo.getEntityName() + ".jsp";
    // }
    // });
    // cfg.setFileOutConfigList(focList);
    // mpg.setCfg(cfg);

    // 执行生成
    ag.execute();
}