package com.gcyang.genetor;
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.NamingStrategy;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
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 + "/yeb-generator/src/main/java");
gc.setAuthor("guobenqi"); //作者
gc.setOpen(false); //是否打开目录
gc.setBaseResultMap(true);//xml开启BaseResultMap
gc.setBaseColumnList(true);//xml 开启BaseColumn
gc.setSwagger2(true); //实体属性 Swagger2 注解
mpg.setGlobalConfig(gc);
// 数据源配置
DataSourceConfig dsc = new DataSourceConfig();
dsc.setUrl("jdbc:mysql://localhost:3306/yeb?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai");
// dsc.setSchemaName("public");
dsc.setDriverName("com.mysql.cj.jdbc.Driver");
dsc.setUsername("root");
dsc.setPassword("123456789g");
mpg.setDataSource(dsc);
// 包配置
PackageConfig pc = new PackageConfig();
//pc.setModuleName(scanner("模块名"));
pc.setParent("com.gcayng.yebserver")
.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
}
};
// 如果模板引擎是 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 + "/yeb-generator/src/main/resources/mapper/" + pc.getModuleName()
+ "/" + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML;
}
});
/*
cfg.setFileCreate(new IFileCreate() {
@Override
public boolean isCreate(ConfigBuilder configBuilder, FileType fileType, String filePath) {
// 判断自定义文件夹是否需要创建
checkDir("调用默认方法创建的目录,自定义目录用");
if (fileType == FileType.MAPPER) {
// 已经生成 mapper 文件判断存在,不想重新生成返回 false
return !new File(filePath).exists();
}
// 允许生成模板文件
return true;
}
});
*/
cfg.setFileOutConfigList(focList);
mpg.setCfg(cfg);
// 配置模板
TemplateConfig templateConfig = new TemplateConfig();
// 配置自定义输出模板
//指定自定义模板路径,注意不要带上.ftl/.vm, 会根据使用的模板引擎自动识别
// templateConfig.setEntity("templates/entity2.java");
// templateConfig.setService();
// templateConfig.setController();
templateConfig.setXml(null);
mpg.setTemplate(templateConfig);
// 策略配置
StrategyConfig strategy = new StrategyConfig();
//数据库表映射到实体的命名策略
strategy.setNaming(NamingStrategy.underline_to_camel);
//数据库表字段映射到实体的命名策略
strategy.setColumnNaming(NamingStrategy.no_change);
//strategy.setSuperEntityClass("你自己的父类实体,没有就不用设置!");
//lombok模型
strategy.setEntityLombokModel(true);
//生成RestController
strategy.setRestControllerStyle(true);
// 公共父类
//strategy.setSuperControllerClass("你自己的父类控制器,没有就不用设置!");
// 写于父类中的公共字段
//strategy.setSuperEntityColumns("id");
strategy.setInclude(scanner("表名,多个英文逗号分割").split(","));
strategy.setControllerMappingHyphenStyle(true);
//表前缀
strategy.setTablePrefix("t_");
mpg.setStrategy(strategy);
mpg.setTemplateEngine(new FreemarkerTemplateEngine());
mpg.execute();
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
基于springboot+vue的在线办公OA系统.zip
共413个文件
xml:175个
class:110个
java:108个
需积分: 5 1 下载量 187 浏览量
2023-08-07
23:17:53
上传
评论
收藏 349KB ZIP 举报
温馨提示
基于java、jsp、servlet、mysql、springboot等技术构建的系统,适合毕设项目、课设作业。资源中的源码都是经过本地编译过可运行的,下载后按照文档配置好环境就可以运行。资源项目的难度比较适中,内容都是经过助教老师审定过的,应该能够满足学习、使用需求,如果有需要的话可以放心下载使用。
资源推荐
资源详情
资源评论
收起资源包目录
基于springboot+vue的在线办公OA系统.zip (413个子文件)
Employee.class 17KB
Salary.class 9KB
CodeGenerator.class 7KB
Admin.class 6KB
Menu.class 6KB
MailLog.class 6KB
EmployeeRemove.class 5KB
SalaryAdjust.class 5KB
EmployeeEc.class 5KB
Appraise.class 4KB
Department.class 4KB
Joblevel.class 4KB
EmployeeTrain.class 4KB
SysMsg.class 4KB
Position.class 4KB
SysMsgContent.class 3KB
Oplog.class 3KB
Role.class 3KB
AdminRole.class 3KB
MenuRole.class 3KB
PoliticsStatus.class 2KB
Nation.class 2KB
CodeGenerator$2.class 2KB
YebServerApplication.class 851B
EmployeeRemoveServiceImpl.class 784B
PoliticsStatusServiceImpl.class 784B
SysMsgContentServiceImpl.class 777B
EmployeeTrainServiceImpl.class 777B
SalaryAdjustServiceImpl.class 770B
DepartmentServiceImpl.class 756B
EmployeeEcServiceImpl.class 756B
AdminRoleServiceImpl.class 749B
AppraiseServiceImpl.class 742B
EmployeeServiceImpl.class 742B
PositionServiceImpl.class 742B
JoblevelServiceImpl.class 742B
MenuRoleServiceImpl.class 742B
MailLogServiceImpl.class 735B
NationServiceImpl.class 728B
SalaryServiceImpl.class 728B
SysMsgServiceImpl.class 728B
AdminServiceImpl.class 721B
OplogServiceImpl.class 721B
RoleServiceImpl.class 714B
MenuServiceImpl.class 714B
PoliticsStatusController.class 558B
EmployeeRemoveController.class 558B
SysMsgContentController.class 555B
EmployeeTrainController.class 554B
YebServerApplicationTests.class 554B
SalaryAdjustController.class 550B
EmployeeEcController.class 542B
DepartmentController.class 541B
CodeGenerator$1.class 541B
AdminRoleController.class 538B
MenuRoleController.class 534B
PositionController.class 533B
JoblevelController.class 533B
AppraiseController.class 533B
EmployeeController.class 533B
MailLogController.class 530B
SysMsgController.class 526B
NationController.class 525B
SalaryController.class 525B
AdminController.class 521B
OplogController.class 521B
RoleController.class 517B
MenuController.class 517B
IEmployeeRemoveService.class 351B
IPoliticsStatusService.class 351B
ISysMsgContentService.class 348B
IEmployeeTrainService.class 348B
ISalaryAdjustService.class 345B
IEmployeeEcService.class 339B
IDepartmentService.class 339B
PoliticsStatusMapper.class 338B
EmployeeRemoveMapper.class 338B
IAdminRoleService.class 336B
SysMsgContentMapper.class 335B
EmployeeTrainMapper.class 335B
IPositionService.class 333B
IJoblevelService.class 333B
IEmployeeService.class 333B
IMenuRoleService.class 333B
IAppraiseService.class 333B
SalaryAdjustMapper.class 332B
IMailLogService.class 330B
ISalaryService.class 327B
ISysMsgService.class 327B
INationService.class 327B
EmployeeEcMapper.class 326B
DepartmentMapper.class 326B
IAdminService.class 324B
IOplogService.class 324B
AdminRoleMapper.class 323B
IRoleService.class 321B
IMenuService.class 321B
JoblevelMapper.class 320B
AppraiseMapper.class 320B
MenuRoleMapper.class 320B
共 413 条
- 1
- 2
- 3
- 4
- 5
资源评论
独处东汉
- 粉丝: 392
- 资源: 822
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功