当前位置:网站首页>Code generator
Code generator
2022-07-29 01:30:00 【Bai Xiaoyun】
Code generator
According to the field name of the database , Generate code template
public static void main(String[] args) {
//1. Get the object of the code generator
AutoGenerator autoGenerator = new AutoGenerator();
// Set database related configuration
DataSourceConfig dataSource = new DataSourceConfig();
dataSource.setDriverName("com.mysql.cj.jdbc.Driver");
dataSource.setUrl("jdbc:mysql://localhost:3306/mybatisplus_db?serverTimezone=UTC");
dataSource.setUsername("root");
dataSource.setPassword("20020630");
autoGenerator.setDataSource(dataSource);
// Set global configuration
GlobalConfig globalConfig = new GlobalConfig();
globalConfig.setOutputDir(System.getProperty("user.dir")+"/mybatispluse01/src/main/java/com"); // Set code generation location
globalConfig.setOpen(true); // Set whether to open the directory where the generated code is located after generation
globalConfig.setAuthor(" Black horse programmer "); // Set the author
globalConfig.setFileOverride(true); // Set whether to overwrite the original generated file
globalConfig.setMapperName("%sDao"); // Set the data layer interface name ,%s As a placeholder , Refers to the module name
globalConfig.setIdType(IdType.ASSIGN_ID); // Set up Id Generation strategy
autoGenerator.setGlobalConfig(globalConfig);
// Set package name related configuration
PackageConfig packageInfo = new PackageConfig();
packageInfo.setParent("com.aaa"); // Set the generated package name , Does not conflict with the location of the code , The two superimpose to form a complete path
packageInfo.setEntity("domain"); // Set entity class package name
packageInfo.setMapper("dao"); // Set the data layer package name
autoGenerator.setPackageInfo(packageInfo);
// Policy settings
StrategyConfig strategyConfig = new StrategyConfig();
strategyConfig.setInclude("tbl_user"); // Set the name of the table currently participating in the generation , Parameters are variable parameters
strategyConfig.setTablePrefix("tbl_"); // Set the prefix name of the database table , Module name = Database table name - Prefix for example : User = tbl_user - tbl_
strategyConfig.setRestControllerStyle(true); // Set whether to enable Rest style
strategyConfig.setVersionFieldName("version"); // Set optimistic lock field name
strategyConfig.setLogicDeleteFieldName("deleted"); // Set the logical deletion field name
strategyConfig.setEntityLombokModel(true); // Set whether to enable lombok
autoGenerator.setStrategy(strategyConfig);
//2. Perform the build operation
autoGenerator.execute();
}
}
边栏推荐
- Flink SQL Hudi actual combat
- [SQL's 18 dragon subduing palms] 01 - Kang long regrets: introductory 10 questions
- Common functions and usage of numpy
- Django使用MySQL数据库已经存在的数据表方法
- [idea] where to use the query field
- 正则校验与时间格式化
- Redis is installed on Linux
- 第二轮Okaleido Tiger热卖的背后,是背后生态机构战略支持
- 18 diagrams, intuitive understanding of neural networks, manifolds and topologies
- Recommended Spanish translation of Beijing passport
猜你喜欢

Docker-compose安装mysql

教你一文解决 js 数字精度丢失问题

【idea】查询字段使用位置

C语言300行代码实现扫雷(可展开+可标记+可更改困难级别)

括号匹配的检验

Self-attention neural architecture search for semantic image segmentation

SQL question brushing: find the last of all employees who have been assigned departments_ Name and first_ Name and Dept_ no

Learning summary of time complexity and space complexity

时间复杂度、空间复杂度的学习总结

PLATO上线LAAS协议Elephant Swap,用户可借此获得溢价收益
随机推荐
body中基本标签
RHCE command practice (II)
SQL injection of DVWA
瑞吉外卖项目实战Day01
梅克尔工作室——HarmonyOS实现列表待办
如何选择专业、安全、高性能的远程控制软件
Linux redis source code installation
els 到底停止
Django uses pymysql module to connect mysql database
Third party login process of flask Weibo
Self-attention neural architecture search for semantic image segmentation
Instruction rearrangement, happens before, as if serial
How to smoothly go online after MySQL table splitting?
JS judge whether array / object array 1 contains array / object array 2
vm options、program arguments、environment property
新1688 API 接入说明
nep 2022 cat
PLATO上线LAAS协议Elephant Swap,用户可借此获得溢价收益
云原生应用综合练习下
Introduction to FLV documents