参数配置文档

配置分两步

1.添加依赖

 <dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.0.6</version>
</dependency> <dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency> <dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
</dependency>

2.新增CodeGenerator类

package com.sswchat;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.InjectionConfig;
import com.baomidou.mybatisplus.generator.config.*;
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine; import java.util.ArrayList;
import java.util.List;
import java.util.Scanner; public class CodeGenerator { public static String scanner(String tip){
Scanner scanner = new Scanner(System.in);
StringBuilder help = new StringBuilder();
help.append("请输入"+tip+":");
System.out.println(help.toString());
if(scanner.hasNext()){
String ipt = scanner.next();
if(StringUtils.isNotEmpty(ipt)){
return ipt;
}
}
throw new MybatisPlusException("请输入正确的"+tip+"!");
} public static void main(String[] args) {
//代码生成器
AutoGenerator mpg = new AutoGenerator(); //全局配置
GlobalConfig gc = new GlobalConfig();
String projectPath = System.getProperty("user.dir");
gc.setOutputDir(projectPath+"/src/main/java");//生成目文件的输出目录
gc.setAuthor("***");//开发人员
gc.setOpen(false);//文件生成后,是否需要打开所在路径
gc.setFileOverride(true);//是否覆盖已有文件
gc.setEnableCache(false);//是否在xml中添加二级缓存设置
gc.setActiveRecord(false);//开启ActiveRecord模式
gc.setBaseResultMap(true);//开启BaseResultMap
gc.setBaseColumnList(true);//开启BaseColumnList
gc.setDateType(DateType.TIME_PACK);//时间类型对应策略
gc.setControllerName("%sController");
gc.setEntityName("%s");//实体命名方式
gc.setServiceName("%sService");
gc.setMapperName("%sMapper");
gc.setXmlName("%sMapper");
gc.setIdType(IdType.AUTO); mpg.setGlobalConfig(gc); //数据源配置
DataSourceConfig dsc = new DataSourceConfig();
dsc.setUrl("jdbc:mysql://localhost:3306/sina?useUnicode=true&useSSL=false&characterEncoding=utf8&serverTimezone=UTC");
dsc.setDriverName("com.mysql.cj.jdbc.Driver");
dsc.setUsername("root");
dsc.setPassword("root");
mpg.setDataSource(dsc); //包配置
PackageConfig pc = new PackageConfig();
pc.setParent("com.sswchat");//父包名,如果为空,将下面子包名必须写全部,否则就只需写子包名
pc.setModuleName(scanner("模块名"));//父包模块名称
mpg.setPackageInfo(pc); //自定义配置
InjectionConfig cfg = new InjectionConfig() {
@Override
public void initMap() { }
}; // 如果模板引擎是 freemarker
String templatePath = "/templates/mapper.xml.ftl"; //自定义输出配置
List<FileOutConfig> fileOutConfigs = new ArrayList<>();
//自定义配置会被优先输出
fileOutConfigs.add(new FileOutConfig(templatePath) {
@Override
public String outputFile(TableInfo tableInfo) {
//自定义输出文件名
return projectPath+"/src/main/com/sswwhat/mapper/mapping/"+tableInfo.getEntityName()+"Mapper"+ StringPool.DOT_XML;
}
}); cfg.setFileOutConfigList(fileOutConfigs);//配置FileOutConfig指定模板文件、输出文件达到自定义文件生成目的
mpg.setCfg(cfg);
mpg.setTemplate(new TemplateConfig().setXml(null)); StrategyConfig strategyConfig = new StrategyConfig();
strategyConfig.setCapitalMode(true)
//这里结合Lombok使用,有true,无false
.setEntityLombokModel(true)
.setNaming(NamingStrategy.underline_to_camel);
strategyConfig.setNaming(NamingStrategy.underline_to_camel);
strategyConfig.setColumnNaming(NamingStrategy.underline_to_camel);
strategyConfig.setSuperEntityClass("com.baomidou.ant.common.BaseEntity");
strategyConfig.setRestControllerStyle(true);
strategyConfig.setSuperControllerClass("com.baomidou.ant.common.BaseController");
//strategyConfig.setInclude();
strategyConfig.setSuperEntityColumns("id");
strategyConfig.setControllerMappingHyphenStyle(true);
strategyConfig.setTablePrefix(pc.getModuleName()+"_");
mpg.setStrategy(strategyConfig);
mpg.setTemplateEngine(new FreemarkerTemplateEngine()); mpg.execute(); }
}

mybatis plus generator工具集成(一)的更多相关文章

  1. mybatis generator工具集成(一)

    第一步,pom中加入 <build> <plugins> <plugin> <groupId>org.springframework.boot</ ...

  2. springboot集成mybatis及mybatis generator工具使用

    原文链接 前言mybatis是一个半自动化的orm框架,所谓半自动化就是mybaitis只支持数据库查出的数据映射到pojo类上,而实体到数据库的映射需要自己编写sql语句实现,相较于hibernat ...

  3. springboot入门(三)-- springboot集成mybatis及mybatis generator工具使用

    前言 mybatis是一个半自动化的orm框架,所谓半自动化就是mybaitis只支持数据库查出的数据映射到pojo类上,而实体到数据库的映射需要自己编写sql语句实现,相较于hibernate这种完 ...

  4. MyBatis之七:使用generator工具

    可以将mybatis理解成一种半自动化orm框架,通过注解或者配置xml映射文件来手写相关sql语句,不能像我之前介绍orm的文章那样全对象化操作数据库增删改查.其实你会发现,手写配置xml映射文件是 ...

  5. mybatis代码生成(generator工具生成代码)

    generator工具生成代码 下载地址     http://pan.baidu.com/s/1bY8C0I

  6. mybatis generator工具的使用

    mybatis反转数据库的配置文件: generatorConfig.xml: <?xml version="1.0" encoding="UTF-8"? ...

  7. 一步步学Mybatis-告别繁琐的配置之Mybatis配置文件生成工具 (7)

    今年是2013年的杀青之日,前几天由于比较忙,没有及时更新本篇的最后一篇东西,前六篇中我们主要都是采用手动配置相关的Mybatis映射文件与相应的接口类与实体类.当然如果在真正的使用过程中,由于业务的 ...

  8. Quartz学习——SSMM(Spring+SpringMVC+Mybatis+Mysql)和Quartz集成详解(四)

    当任何时候觉你得难受了,其实你的大脑是在进化,当任何时候你觉得轻松,其实都在使用以前的坏习惯. 通过前面的学习,你可能大致了解了Quartz,本篇博文为你打开学习SSMM+Quartz的旅程!欢迎上车 ...

  9. Quartz学习——SSMM(Spring+SpringMVC+Mybatis+Mysql)和Quartz集成详解(转)

    通过前面的学习,你可能大致了解了Quartz,本篇博文为你打开学习SSMM+Quartz的旅程!欢迎上车,开始美好的旅程! 本篇是在SSM框架基础上进行的. 参考文章: 1.Quartz学习——Qua ...

随机推荐

  1. 【LeetCode 96】不同的二叉搜索树

    题目链接 [题解] 我们可以枚举这棵树的根节点在i处. 现在问题就变成. 1..i-1这i-1个节点组成的树和i+1..n这n-i个节点组成的树的个数的问题了. 假设他们俩的结果分别是cnt1和cnt ...

  2. E: Could not get lock /var/lib/dpkg/lock-frontend - open (11: Resource temporarly unavailable)

    1. 问题详细提示如下: E: Could not get lock /var/lib/dpkg/lock-frontend - open (11: Resource temporarly unava ...

  3. [CSP-S模拟测试]:z(模拟+map+小根堆)

    题目背景 $\frac{1}{4}$遇到了一道水题,$eooooo$完全不会做,于是去请教小$D$.结果小$D$已经去了阿塞拜疆,于是,$\frac{1}{4}$只好来问你,这道题是这样的: 题目描述 ...

  4. Cent OS (一)Cents OS的基本安装

    1.实验环境: VMware Workstation Pro   14 Pro Cent OS 7 系列. 2. 镜像地址传送门: 阿里云开源镜像站:http://mirrors.aliyun.com ...

  5. php面试专题---2、常量及数据类型考点

    php面试专题---2.常量及数据类型考点 一.总结 一句话总结: 变量为null和变量判断为false的情况需要仔细注意下 1.PHP中字符串可以使用哪三种定义方法以及各自的区别是什么? 单引号:不 ...

  6. git设置忽略文件.gitignore

    在仓库目录下新建一个名为.gitignore的文件(因为是点开头,没有文件名,没办法直接在windows目录下直接创建,必须通过右键Git Bash,按照linux的方式来新建.gitignore文件 ...

  7. Java + selenium 元素定位(3)之By TagName

    本篇介绍findElement接口中的By TagName方法.首先,要知道什么是tagname.之前我们使用F12开发者工具查看网页元素是,发现每行代码前都有<input>.<bo ...

  8. Learning OSG programing---osgwindows

    /* OpenSceneGraph example, osgwindows. * * Permission is hereby granted, free of charge, to any pers ...

  9. MSF——信息收集(四)

    MSF系列: MSF——基本使用和Exploit模块(一) MSF——Payload模块(二) MSF——Meterpreter(三) MSF——信息收集(四) 发现和端口扫描 Nmap扫描 db_n ...

  10. Npm使用遇到的问题解决

    0.运行项目: 1)git clone 项目 2)项目根目录执行npm install安装依赖 3)执行npm run dev启动 1.安装cnpm: npm install -g cnpm --re ...