package com.ulic.seckill;
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.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.FileOutConfig;
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.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.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
/**
* 执行 main 方法控制台输入模块表名回车自动生成对应项目目录中
*
* @author yangdw002
* @since 1.0.0
*/
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.isNotBlank(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("yangdw002");
// 打开输出目录
gc.setOpen(false);
// xml开启 BaseResultMap
gc.setBaseResultMap(true);
// xml 开启BaseColumnList
gc.setBaseColumnList(true);
// 日期格式,采用Date
gc.setDateType(DateType.ONLY_DATE);
mpg.setGlobalConfig(gc);
// 数据源配置
DataSourceConfig dsc = new DataSourceConfig();
dsc.setUrl("jdbc:mysql://10.18.1.82:33062/ktdev?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia"
+ "/Shanghai");
dsc.setDriverName("com.mysql.jdbc.Driver");
dsc.setUsername("ktdev");
dsc.setPassword("Awds_0202");
mpg.setDataSource(dsc);
// 包配置
PackageConfig pc = new PackageConfig();
pc.setParent("com.ulic.seckill").setEntity("pojo").setMapper("mapper").setService("service")
.setServiceImpl("service.impl").setController("controller");
mpg.setPackageInfo(pc);
// 自定义配置
InjectionConfig cfg = new InjectionConfig() {
@Override
public void initMap() {
// to do nothing
Map<String, Object> map = new HashMap<>();
map.put("date1", "1.0.0");
this.setMap(map);
}
};
// 如果模板引擎是 freemarker
String templatePath = "/templates/mapper.xml.ftl";
// 如果模板引擎是 velocity
// String templatePath = "/templates/mapper.xml.vm";
// 自定义输出配置
List<FileOutConfig> focList = new ArrayList<>();
// 自定义配置会被优先输出
focList.add(new FileOutConfig(templatePath) {
@Override
public String outputFile(TableInfo tableInfo) {
// 自定义输出文件名 , 如果你 Entity 设置了前后缀、此处注意 xml 的名称会跟着发生变化!!
return projectPath + "/src/main/resources/mapper/" + tableInfo.getEntityName() + "Mapper"
+ StringPool.DOT_XML;
}
});
cfg.setFileOutConfigList(focList);
mpg.setCfg(cfg);
// 配置模板
TemplateConfig templateConfig = new TemplateConfig().setEntity("templates/entity.java")
.setMapper("templates/mapper.java")
.setService("templates/service.java").setServiceImpl("templates/serviceImpl.java")
.setController("templates/controller.java");
templateConfig.setXml(null);
mpg.setTemplate(templateConfig);
// 策略配置
StrategyConfig strategy = new StrategyConfig();
// 数据库表映射到实体的命名策略
strategy.setNaming(NamingStrategy.underline_to_camel);
// 数据库表字段映射到实体的命名策略
strategy.setColumnNaming(NamingStrategy.underline_to_camel);
// lombok模型
strategy.setEntityLombokModel(true);
// 生成 @RestController 控制器
// strategy.setRestControllerStyle(true);
strategy.setInclude(scanner("表名,多个英文逗号分割").split(","));
strategy.setControllerMappingHyphenStyle(true);
// 表前缀
strategy.setTablePrefix("t_");
mpg.setStrategy(strategy);
mpg.setTemplateEngine(new FreemarkerTemplateEngine());
mpg.execute();
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
mybatisPlus逆向生成工程
共38个文件
class:10个
java:8个
xml:5个
需积分: 50 1 下载量 125 浏览量
2022-06-16
14:17:34
上传
评论
收藏 66KB 7Z 举报
温馨提示
用于mybatisplus逆向生成工程,可以快速生成crontroller,service,mapper,pojo等包和类,快速开发。pojo里面和数据库的表是绑定的,一般是驼峰命名规则。此工程也可以做mybatisplus学习工程使用,可以快速上手,使用maven构建的。
资源详情
资源评论
资源推荐
收起资源包目录
generator.7z (38个子文件)
generator
pom.xml 2KB
target
test-classes
com
ulic
seckill
GeneratorApplicationTests.class 406B
classes
META-INF
maven
com.ulic
generator
pom.xml 2KB
pom.properties 217B
MANIFEST.MF 260B
application.properties 1B
com
ulic
seckill
CodeGenerator$1.class 944B
pojo
UserSeckill.class 4KB
mapper
UserSeckillMapper.class 321B
GeneratorApplication.class 718B
CodeGenerator.class 7KB
controller
UserSeckillController.class 525B
service
IUserSeckillService.class 334B
impl
UserSeckillServiceImpl.class 739B
CodeGenerator$2.class 1KB
mapper
UserSeckillMapper.xml 936B
mvnw 10KB
.settings
org.eclipse.m2e.core.prefs 90B
org.eclipse.wst.common.project.facet.core.xml 145B
org.eclipse.core.resources.prefs 155B
org.eclipse.jdt.core.prefs 243B
src
test
java
com
ulic
seckill
GeneratorApplicationTests.java 94B
main
resources
application.properties 1B
templates
static
mapper
UserSeckillMapper.xml 936B
java
com
ulic
seckill
CodeGenerator.java 5KB
GeneratorApplication.java 315B
pojo
UserSeckill.java 935B
mapper
UserSeckillMapper.java 307B
controller
UserSeckillController.java 347B
service
IUserSeckillService.java 308B
impl
UserSeckillServiceImpl.java 542B
.project 1KB
.classpath 1KB
.gitignore 395B
.mvn
wrapper
maven-wrapper.jar 57KB
maven-wrapper.properties 233B
mvnw.cmd 7KB
HELP.md 1KB
共 38 条
- 1
david168520
- 粉丝: 5
- 资源: 18
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- STM8L101F3P6单片机+CC1100模块433M遥控器设计硬件(原理图+PCB)工程文件.zip
- 上传下载铁人下载系统 Liuxing 1.0-liuxing1.0.rar
- 南京邮电大学数学实验实力雄厚,凭借其优秀的师资力量、丰富的实践教学资源和卓越的科研成果,成为国内一流的数学实验教学和科研基地
- 【火爆朋友圈的今天吃什么源码 v1.0】随机的为用户带来每一天的用餐选择和推荐.rar
- MPU6050中文版数据手册
- 上传下载手机电影下载-mobiledy.rar
- 响应式旅游网站源码下载 马尔代夫旅游网站.rar
- CMS小涴熊漫画连载系统漫画网站源码 带采集API.rar
- 福袋点点.apk
- 基于STM32的电子秤采用0.96寸OLED显示UI界面源码.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0