参考Ibase4j 

          1.首先在pom中引用mybatis-plus jar

  
</dependency>
<!-- mybatis -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus</artifactId>
<version>${mybatis-plus.version}</version>
</dependency>  

2.编写

    Generator类编写 如下
package org;

import java.util.HashMap;
import java.util.Map; 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; /**
* 代码生成 注意:不生成service接口 注意:不生成service接口 注意:不生成service接口
*
* @author ShenHuaJie
*/
public class Generator {
/**
* 测试 run 执行 注意:不生成service接口 注意:不生成service接口 注意:不生成service接口
* <p>
* 配置方法查看 {@link ConfigGenerator}
* </p>
*/
public static void main(String[] args) {
AutoGenerator mpg = new AutoGenerator();
// 全局配置
GlobalConfig gc = new GlobalConfig();
gc.setOutputDir("D://");
gc.setFileOverride(false);
gc.setActiveRecord(false);
gc.setEnableCache(false);// XML 二级缓存
gc.setBaseResultMap(false);// XML ResultMap
gc.setBaseColumnList(false);// XML columList
gc.setOpen(false);
gc.setAuthor("ShenHuaJie");
// 自定义文件命名,注意 %s 会自动填充表实体属性!
// gc.setMapperName("%sDao");
// gc.setXmlName("%sDao");
gc.setServiceImplName("%sService");
// gc.setServiceImplName("%sServiceDiy");
// gc.setControllerName("%sAction");
mpg.setGlobalConfig(gc);
// 数据源配置
DataSourceConfig dsc = new DataSourceConfig();
dsc.setDbType(DbType.MYSQL);
dsc.setDriverName("com.mysql.jdbc.Driver");
dsc.setUsername("root");
dsc.setPassword("root");
dsc.setUrl("jdbc:mysql://127.0.0.1:3306/iBase4J?characterEncoding=utf8");
mpg.setDataSource(dsc);
// 策略配置
StrategyConfig strategy = new StrategyConfig();
// strategy.setTablePrefix("sys_");// 此处可以修改为您的表前缀
strategy.setNaming(NamingStrategy.underline_to_camel);// 表名生成策略
strategy.setInclude(new String[] { "sys_test" }); // 需要生成的表
// strategy.setExclude(new String[]{"test"}); // 排除生成的表
// 字段名生成策略
strategy.setFieldNaming(NamingStrategy.underline_to_camel);
// 自定义实体父类
strategy.setSuperEntityClass("org.ibase4j.core.base.BaseModel");
// 自定义实体,公共字段
strategy.setSuperEntityColumns(
new String[] { "id_", "enable_", "remark_", "create_by", "create_time", "update_by", "update_time" });
// 自定义 mapper 父类
strategy.setSuperMapperClass("org.ibase4j.core.base.BaseMapper");
// 自定义 service 父类
strategy.setSuperServiceImplClass("org.ibase4j.core.base.BaseService");
// 自定义 service 实现类父类
// strategy.setSuperServiceImplClass("org.ibase4j.core.base.BaseService");
// 自定义 controller 父类
strategy.setSuperControllerClass("org.ibase4j.core.base.AbstractController");
// 【实体】是否生成字段常量(默认 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("org.ibase4j");
pc.setEntity("model");
pc.setMapper("mapper");
pc.setXml("mapper.xml");
pc.setServiceImpl("service");
pc.setService("ignore");
pc.setController("web");
mpg.setPackageInfo(pc);
// 注入自定义配置,可以在 VM 中使用 cfg.abc 设置的值
InjectionConfig cfg = new InjectionConfig() {
public void initMap() {
Map<String, Object> map = new HashMap<String, Object>();
map.put("providerClass", "ISysProvider");
this.setMap(map);
}
};
mpg.setCfg(cfg);
// 自定义模板配置,可以 copy 源码 mybatis-plus/src/main/resources/template 下面内容修改,
// 放置自己项目的 src/main/resources/template 目录下, 默认名称一下可以不配置,也可以自定义模板名称
TemplateConfig tc = new TemplateConfig();
tc.setEntity("tpl/entity.java.vm");
tc.setMapper("tpl/mapper.java.vm");
tc.setXml("tpl/mapper.xml.vm");
tc.setService("tpl/service.java.vm");
tc.setController("tpl/controller.java.vm");
mpg.setTemplate(tc);
// 执行生成
mpg.execute();
}
}

代码模板可以自己修改 也可以直接从jar中拿到 如下图

												

最新文章

  1. According to TLD or attribute directive in tag file, attribute end does not accept any expressions
  2. ViewHolder数据错乱BUG
  3. Karma:1. 集成 Karma 和 Jasmine 进行单元测试
  4. jquery的异步获取返回值为中文时乱码解决方法
  5. JavaScript 类型转换
  6. PHP操作数据库类
  7. NavigationBar的简单设置
  8. 《JavaScript 闯关记》之初探
  9. 编译kernel:内核makefile的作用
  10. 解决win10 关键错误开始菜单和cortana无法工作 的问题(转-真的成功了)
  11. 天气渐热,来片雪花降降温——Android自定义SurfaceView实现雪花效果
  12. 自己动手写fullPage插件
  13. Java逆向武器库_反编译工具
  14. ios和android 浏览器适配问题总结
  15. Docker镜像的使用
  16. Codeforces Round #258 (Div. 2) . Sort the Array 贪心
  17. Notepad++ 删除空白行的方法
  18. Webpack之Code Splitting 代码分块
  19. 支撑大规模公有云的Kubernetes改进与优化 (1)
  20. MVC使用Dotnet.HighCharts做图表01,区域图表

热门文章

  1. 单一功能学习——百度AI之身份证识别
  2. Graham扫描法
  3. js之选项卡效果(淘宝侧边栏)
  4. HDU - 2973:YAPTCHA (威尔逊定理)
  5. HihoCoder 1044 垃圾清理 (优化:状态压缩)
  6. Windows10安装MySQL8.0
  7. Git与github常用命令
  8. 三分钟教你同步 Visual Studio Code 设置
  9. jasmine 使用
  10. 干货:这也许是最全面透彻的一篇RabbitMQ指南!