Mybatis-Plus 3.0代码生成器
package com.kyplatform.generator; import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.*;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy; import java.util.Scanner; /**
* mybatis代码生成器
*/
public class CodeGenerator {
/**
* <p>
* 读取控制台内容
* </p>
*/
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("zhicaili");//开发人员
gc.setOpen(true);//是否打开输出目录
gc.setServiceName("%sService");//service 命名方式
gc.setServiceImplName("%sServiceImpl");//service impl 命名方式
// 自定义文件命名,注意 %s 会自动填充表实体属性!
gc.setMapperName("%sMapper");
gc.setXmlName("%sMapper");
gc.setFileOverride(true);
gc.setActiveRecord(true);
gc.setEnableCache(false);// XML 二级缓存
gc.setBaseResultMap(true);// XML ResultMap
gc.setBaseColumnList(false);// XML columList
mpg.setGlobalConfig(gc); // 数据源配置
DataSourceConfig dsc = new DataSourceConfig();
dsc.setUrl("jdbc:mysql://127.0.0.1:3306/xxxxx?useUnicode=true&useSSL=false&characterEncoding=utf8");
// dsc.setSchemaName("public"); 数据库 schema name
dsc.setDriverName("com.mysql.jdbc.Driver");
dsc.setUsername("root");
dsc.setPassword("******");
mpg.setDataSource(dsc); // 包配置
PackageConfig pc = new PackageConfig();
//pc.setModuleName(scanner("模块名"));//父包模块名
pc.setParent("com.kyplatform.admin");//父包名。// 自定义包路径 如果为空,将下面子包名必须写全部, 否则就只需写子包名
pc.setEntity("pojo");
pc.setService("service");
pc.setServiceImpl("service.impl");
pc.setController("controller");//设置控制器包名
mpg.setPackageInfo(pc); // 自定义配置
/* InjectionConfig cfg = new InjectionConfig() {
@Override
public void initMap() {
// to do nothing
}
};
List<FileOutConfig> focList = new ArrayList<>();
focList.add(new FileOutConfig("/templates/mapper.xml.ftl") {
@Override
public String outputFile(TableInfo tableInfo) {
// 自定义输入文件名称
return projectPath + "/src/main/resources/mapper/" + pc.getModuleName()
+ "/" + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML;
}
});*/
/* cfg.setFileOutConfigList(focList);
mpg.setCfg(cfg);*/
mpg.setTemplate(new TemplateConfig().setXml(null)); // 策略配置
StrategyConfig strategy = new StrategyConfig();
strategy.setNaming(NamingStrategy.underline_to_camel);//数据库表映射到实体的命名策略
strategy.setColumnNaming(NamingStrategy.underline_to_camel);//数据库表字段映射到实体的命名策略, 未指定按照 naming 执行
// strategy.setSuperEntityClass("com.baomidou.ant.common.BaseEntity");//自定义继承的Entity类全称,带包名
strategy.setEntityLombokModel(true);//【实体】是否为lombok模型(默认 false)
strategy.setRestControllerStyle(true);//生成 @RestController 控制器
//strategy.setSuperControllerClass("com.baomidou.ant.common.BaseController");//自定义继承的Controller类全称,带包名
strategy.setInclude("tb_user","tb_organization","tb_person","tb_signin","tb_sys_config","tb_sys_log");//需要包含的表名,允许正则表达式
//strategy.setSuperEntityColumns("id");//自定义基础的Entity类,公共字段
strategy.setControllerMappingHyphenStyle(true);//驼峰转连字符
strategy.setTablePrefix("tb_");//表前缀
mpg.setStrategy(strategy);
//mpg.setTemplateEngine(new FreemarkerTemplateEngine());
mpg.execute();
} }
Mybatis-Plus 3.0代码生成器的更多相关文章
- mybatis plus3.1.0 热加载mapper
今天又开始写业务代码了,每次修改SQL都要重启服务,实在是浪费时间. 想起之前研究过的<mybatis plus3.1.0 热加载mapper>,一直没有成功,今天静下心来分析了问题,终于 ...
- springboot项目war包部署及出现的问题Failed to bind properties under 'mybatis.configuration.mapped-statements[0].
1.修改pom文件 修改打包方式 为war: 添加tomcat使用范围,provided的意思即在发布的时候有外部提供,内置的tomcat就不会打包进去 <groupId>com.scho ...
- mybatis入门篇:代码生成器(MyBatis Generator)
这篇文章只是按照自己的需要去配置代码生成器,未对所有配置进行讲解,需要了解具体详情的,请到官网查阅文档.传送门:http://www.mybatis.org/generator/ 1.首先引入相关的依 ...
- spring整合mybatis,springMVC的0配置文件方式
0配置文件的形式主要是采用spring3.0提供的@configuration注解和spring容器在启动的时候会加载实现了WebApplicationInitializer的类,并调用其onStar ...
- mybatis {arg0} 与 {0}
解决方案: MyBatis的XML的配置文件中声明设置属性的useActualParamName参数值为假 <setting name="useActualParamName" ...
- mybatis将传入0识别成空字符串
mybatis将传入的Integer类型的0被识别成空字符串,网上的解决办法: <if test="status != null and status != '' or status ...
- SpringBoot整合MyBatis与MySql8.0
一.前言 之前已经有一篇文章讨论过SpringBoot整合MyBatis,因而此篇不在重复累赘,本文主要是最新版的SpringBoot2.0与MyBatis.最新MySQL8.0整合过程中遇到的问题进 ...
- Mybatis 3.3.0 Log4j配置
最近做一个SSM学习项目,配置log4j,mybatis用下面的方式配置,不管用,打印不出执行的SQL语句. log4j.logger.java.sql.Connection=DEBUGlog4j.l ...
- mybatis理解(0)
随机推荐
- Java 模板模式
定义:定义了一个算法的骨架,并允许子类为一个或多个步骤提供实现 模板方法使得子类可以在不改变算法的结构的情况下,重新定义算法的某些步骤 类型:行为型 一次性实现一个算法的不变的部分,并将可变的行为留给 ...
- MySQL This function has none of DETERMINISTIC, NO SQL...错误1418 的原因分析及解决方法 (转)
解决方法: 解决办法也有两种, 第一种是在创建子程序(存储过程.函数.触发器)时,声明为DETERMINISTIC或NO SQL与READS SQL DATA中的一个, 例如: CREATE DEFI ...
- .NET Core 添加Java 服务引用(WebService) 曲折历程(一)
背景: 需要在HangFire定时任务中加入请求Java开发的WebService接口.定时获取数据同步数据.现有的代码是在VS2017 ,.Net Core 下创建的,添加WS发现系统不支持. 在C ...
- thinkphp使用PHPExcel导出
thinkphp3. 将PHPExcel下载包放在项目\ThinkPHP\Library\Vendor\PHPExcel thinkphp5 将PHPExcel下载包放在项目\vendor\PHPEx ...
- scrapy相关 通过设置 FEED_EXPORT_ENCODING 解决 unicode 中文写入json文件出现`\uXXXX`
0.问题现象 爬取 item: 2017-10-16 18:17:33 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.hu ...
- 【Android】webview javascript 注入方法
Android中向webview注入js代码可以通过webview.loadUrl("javascript:xxx")来实现,然后就会执行javascript后面的代码. 但是当需 ...
- python运算符——比较运算符
比较运算符的运算结果会得到一个bool类型,也就是逻辑判定,要么是真True,要不就是False 大于“>” 小于“<” 不说了,看看不等于,用“!=”表示.大于等于“>=”和小 ...
- [转自大神]js拖拽小总结
https://blog.csdn.net/u013040887/article/details/83059094 权侵删 这里写的是一个原生js实现拖拽的效果,首先: 1.实现拖拽的三大事件,是要首 ...
- hdu5705
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5705 题目: Problem Description Given a time HH:MM:SS an ...
- GA:利用GA对一元函数进行优化过程,求x∈(0,10)中y的最大值——Jason niu
x = 0:0.01:10; y = x + 10*sin(5*x)+7*cos(4*x); figure plot(x, y) xlabel('independent variable') ylab ...