mybitaPlus的使用
参考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中拿到 如下图

mybitaPlus的使用的更多相关文章
- My way to Python - Day012 - 消息中间件
消息中间件介绍 消息中间件的概念 消息中间件是在消息传输过程中保存消息的容器.消息中间件在将消息从它的源中继到它的目标时充当中间人的作用.队列的主要作用是提供路由并保证消息的传递:如果发生消息接收者不 ...
随机推荐
- 大牛deep learning入门教程
雷锋网(搜索"雷锋网"公众号关注)按:本文由Zouxy责编,全面介绍了深度学习的发展历史及其在各个领域的应用,并解释了深度学习的基本思想,深度与浅度学习的区别和深度学习与神经网络之 ...
- Git 过滤文件,控制上传
在Git的版本控制中,可能有些文件是不需要加入控制的,那我们在提交代码时就需要忽略这些文件,下面讲讲应该怎么给Git配置一些忽略规则. 有三种方法可以忽略掉这些文件,这三种方法都能达到目的,只不过适用 ...
- VS 工具箱 Dev控件显示
工具箱修复Dev控件显示 用VS2010新打开一个项目,居然发现工具箱里边没了Dev控件. 命令提示符定位到Dev控件的安装目录下的\Components\Tools文件夹下,执行如下命令 添加:To ...
- RabbitMQ Study
python pika install: pip install pika Chinese rabbitmq doc: http://rabbitmq.mr-ping.com/PIKA lib doc ...
- UWP 中的 LaunchUriAsync,使用默认浏览器或其他应用打开链接
古老的 Win32 应用启动其他程序太过方便,以至于一部分开发者都已经不记得 Windows 能通过关联协议的方式通过统一资源定位符(URI)来启动应用程序了. 转到 UWP 后,使用 URI 启动应 ...
- PHP 数组转json_encode,单个数组下标为了0时不对??
在 php 数组转json时,假如 有一个数组下标是顺序的,他json_encode后会直接变成一个简版二维json, $arr = ['1'=>1,'2'=>2]; echo (json ...
- C#-StructLayoutAttribute(结构体布局)
struct实例字段的内存布局(Layout)和大小(Size) 在C/C++中,struct类型中的成员的一旦声明,则实例中成员在内存中的布局(Layout)顺序就定下来了,即与成员声明的顺序相同, ...
- asp.net如何判断服务器上的目录或文件是否存在
asp.net判断服务器上的目录或文件是否存在!(实例) // ======================================================= [判断文件是否存在] u ...
- spring cloud feign 接口继承以及参数传递的问题
1. 优势 可以使用maven 进行访问,实现代码的共享,减少跨服务调用服务编写的问题 2. 使用 定义接口 publicinterfaceIUserService{ @Requ ...
- 去掉UIWebView上下滚动出边界时的黑色阴影
for (UIView *viewin [_webViewsubviews]){ if ([viewisKindOfClass:[UIScrollView class]]){ for (UIView ...