基础权限开发框架 BMS = Spring boot + Mybatis plus + Shiro
 
 
BMS
/

bms-admin 

/

src 

/

main 

/

java 

/

com 

/

xj 

/

admin 

/

CodeGenerator.java

 CodeGenerator.java 4.99 KB →  xjher 提交于 11月前 . update
package com.xj.admin;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.InjectionConfig;
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.TemplateConfig;
import com.baomidou.mybatisplus.generator.config.rules.DbType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
/**
* <p>
* 代码生成器演示
* </p>
*/
public class CodeGenerator {
public static void main(String[] args) {
AutoGenerator mpg = new AutoGenerator();
// 全局配置
GlobalConfig gc = new GlobalConfig();
gc.setOutputDir("D://");
gc.setFileOverride(true);
gc.setActiveRecord(true);
gc.setEnableCache(true);// XML 二级缓存
gc.setBaseResultMap(true);// XML ResultMap
gc.setBaseColumnList(false);// XML columList
gc.setAuthor("xj");
// 自定义文件命名,注意 %s 会自动填充表实体属性!
// gc.setMapperName("%sDao");
// gc.setXmlName("%sDao");
// gc.setServiceName("MP%sService");
// gc.setServiceImplName("%sServiceDiy");
// gc.setControllerName("%sAction");
mpg.setGlobalConfig(gc);
// 数据源配置
DataSourceConfig dsc = new DataSourceConfig();
dsc.setDbType(DbType.MYSQL);
dsc.setDriverName(readValue("spring.datasource.driver-class-name"));
dsc.setUsername(readValue("spring.datasource.username"));
dsc.setPassword(readValue("spring.datasource.password"));
dsc.setUrl(readValue("spring.datasource.url"));
mpg.setDataSource(dsc);
// 策略配置
StrategyConfig strategy = new StrategyConfig();
//strategy.setTablePrefix("bmd_");// 此处可以修改为您的表前缀
strategy.setNaming(NamingStrategy.underline_to_camel);// 表名生成策略
strategy.setInclude(new String[] { "tb_dict" }); // 需要生成的表
// strategy.setExclude(new String[]{"test"}); // 排除生成的表
// 字段名生成策略
strategy.setDbColumnUnderline(true);
// 自定义实体父类
// strategy.setSuperEntityClass("com.baomidou.demo.TestEntity");
// 自定义实体,公共字段
// strategy.setSuperEntityColumns(new String[] { "test_id", "age" });
// 自定义 mapper 父类
// strategy.setSuperMapperClass("com.baomidou.demo.TestMapper");
// 自定义 service 父类
// strategy.setSuperServiceClass("com.baomidou.demo.TestService");
// 自定义 service 实现类父类
// strategy.setSuperServiceImplClass("com.baomidou.demo.TestServiceImpl");
// 自定义 controller 父类
// strategy.setSuperControllerClass("com.baomidou.demo.TestController");
// 【实体】是否生成字段常量(默认 false)
// public static final String ID = "test_id";
// strategy.setEntityColumnConstant(true);
// 【实体】是否为构建者模型(默认 false)
// public User setName(String name) {this.name = name; return this;}
// strategy.setEntityBuliderModel(true);
mpg.setStrategy(strategy);
// 包配置
PackageConfig pc = new PackageConfig();
pc.setParent("com.xj.common.bussiness");
pc.setModuleName("dict");
mpg.setPackageInfo(pc);
// 注入自定义配置,可以在 VM 中使用 cfg.abc 设置的值
InjectionConfig cfg = new InjectionConfig() {
@Override
public void initMap() {
Map<String, Object> map = new HashMap<String, Object>();
map.put("abc", this.getConfig().getGlobalConfig().getAuthor() + "-mp");
this.setMap(map);
}
};
mpg.setCfg(cfg);
// 自定义模板配置,可以 copy 源码 mybatis-plus/src/main/resources/template 下面内容修改,
// 放置自己项目的 src/main/resources/template 目录下, 默认名称一下可以不配置,也可以自定义模板名称
TemplateConfig tc = new TemplateConfig();
tc.setController("/template/controller.vm");
// tc.setEntity("...");
// tc.setMapper("...");
// tc.setXml("...");
// tc.setService("...");
// tc.setServiceImpl("...");
mpg.setTemplate(tc);
// 执行生成
mpg.execute();
// 打印注入设置
System.err.println(mpg.getCfg().getMap().get("abc"));
}
//根据key读取value
public static String readValue(String key) {
String filePath =CodeGenerator.class.getClassLoader().getResource("application.properties").getPath();
Properties props = new Properties();
try {
InputStream in = new BufferedInputStream (new FileInputStream(filePath));
props.load(in);
String value = props.getProperty (key);
System.out.println(key+value);
return value;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}

mark CodeGenerator的更多相关文章

  1. java.io.IOException: mark/reset not supported

    java.io.IOException: mark/reset not supported at java.io.InputStream.reset(InputStream.java:348) at ...

  2. [mark] 使用Sublime Text 2时如何将Tab配置为4个空格

    在Mac OS X系统下,Sublime Text是一款比较赞的编辑器. 作为空格党的自觉,今天mark一下使用Sublime Text 2时如何将Tab配置为4个空格: 方法来自以下两个链接: ht ...

  3. 特邀美国EMC实战专家Mark来华授课

    “轻松搞定EMC-PCB和系统设计”课程介绍 本次课程特邀美国EMC领域权威专家Mark Montrose主讲,将涵盖满足产品电磁兼容性和信号完整性的基本原理.课程涉及多个领域,不仅仅针对PCB设计, ...

  4. 如何撤销 PhpStorm/Clion 等 JetBrains 产品的 “Mark as Plain Text” 操作 ?

    当把某个文件“Mark as Plain Text”时,该文件被当做普通文本,就不会有“代码自动完成提示”功能,如下图所示: 但是呢,右键菜单中貌似没有 相应的撤销 操作, 即使是把它删除,再新建一个 ...

  5. vim - mark

    Using markshttp://vim.wikia.com/wiki/Using_marks1. There is no visible indication of where marks are ...

  6. 根据大小生成对应尺寸网络图片的网址(mark)

    当开发程序时,需要用到一些临时图片替代时,需要快速生成的话,以下的几个网址可提供帮助.mark一下,方便以后使用. http://lorempixel.com/http://placehold.it/ ...

  7. vim 标记 mark 详解 (转载)

    http://www.cnblogs.com/jianyungsun/archive/2011/02/14/1954057.html Vim 允许你在文本中放置自定义的标记.命令 "ma&q ...

  8. CodeGenerator.cs

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace CiCe ...

  9. InputStream复用,mark和reset

    markSupported InputStream是否支持mark,默认不支持. public boolean markSupported() { return false; } InputStrea ...

随机推荐

  1. intel vt

    EPT和VPID技术是内存虚拟化技术, 是页表扩充技术Extended Page Table (EPT) 的缩写, 是VT-x技术的一部分. 内存虚拟化的主要任务是实现地址空间的虚拟化,内存虚拟化是通 ...

  2. Redhat、Centos等系统配置进行网络配置的方法

    配置文件(Redhat) /etc/sysconfig/network-scripts/* : 网卡/etc/sysconfig/network-scripts/ifcfg-eth0/etc/reso ...

  3. Jenkins 持续集成综合实战

    Jenkins 是一款流行的开源持续集成(Continuous Integration)工具,广泛用于项目开发,具有自动化构建.测试和部署等功能.本文以 CentOS7 环境为例,总结了 Jenkin ...

  4. 6、java5线程池之固定大小线程池newFixedThreadPool

    JDK文档说明: 创建一个可重用固定线程数的线程池,以共享的无界队列方式来运行这些线程.在任意点,在大多数 nThreads 线程会处于处理任务的活动状态.如果在所有线程处于活动状态时提交附加任务,则 ...

  5. Ubuntu16.04下添加打印机FujiXerox CP116w

    今天要打印一份北马的成绩单, 不想重启机器了, 在Ubuntu下尝试添加打印机, 最后成功了, 记录一下 打印机型号是FujiXerox CP116w, 通过WIFI连接的, 在Ubuntu16.04 ...

  6. 基于springboot跟poi封装的最便捷的excel导出

    发布时间:2018-11-15   技术:springboot1.5.6 + maven3.0.5 + jdk1.8   概述 Springboot最便捷的Excel导出,只需要一个配置文件即可搞定 ...

  7. 【TP3.2.X】(同样适用于OT) 设置单入口index.php文件,区分PC/WAP/Wechat 三个终端

    1.目的:本教程适用于 OneThink1.0.或者TP3.2.X 系列,达到单入口index.php文件,区分PC/WAP/Wechat 三个终端 2.启发至 : http://www.thinkp ...

  8. Xcode全局替换内容,一键Replace

    有时需要在整个项目里,全局修改某一段话或文字,可以这样快速实现: 1.打开查找功能 2.输入你要替换的内容 比如,我这边想全局修改作者名称 3.点击Find,会出现一个框,会有replace出来,就和 ...

  9. CSS特效(弧光效果)

    代码很简单, 根据需要修改标签class和弧光效果的宽高位置就可以了. <!DOCTYPE html> <html lang="en"> <head& ...

  10. Instagram/IGListKit 实践谈(UICollectionView框架)

    简单介绍 IGListKit是Instagram推出的新的UICollectionView框架,使用数据驱动,旨在创造一个更快更灵活的列表控件. github地址:https://github.com ...