当前位置:网站首页>代码生成器
代码生成器
2022-07-29 00:26:00 【白小筠】
代码生成器
根据数据库的字段名,生成代码模板
public static void main(String[] args) {
//1.获取代码生成器的对象
AutoGenerator autoGenerator = new AutoGenerator();
//设置数据库相关配置
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);
//设置全局配置
GlobalConfig globalConfig = new GlobalConfig();
globalConfig.setOutputDir(System.getProperty("user.dir")+"/mybatispluse01/src/main/java/com"); //设置代码生成位置
globalConfig.setOpen(true); //设置生成完毕后是否打开生成代码所在的目录
globalConfig.setAuthor("黑马程序员"); //设置作者
globalConfig.setFileOverride(true); //设置是否覆盖原始生成的文件
globalConfig.setMapperName("%sDao"); //设置数据层接口名,%s为占位符,指代模块名称
globalConfig.setIdType(IdType.ASSIGN_ID); //设置Id生成策略
autoGenerator.setGlobalConfig(globalConfig);
//设置包名相关配置
PackageConfig packageInfo = new PackageConfig();
packageInfo.setParent("com.aaa"); //设置生成的包名,与代码所在位置不冲突,二者叠加组成完整路径
packageInfo.setEntity("domain"); //设置实体类包名
packageInfo.setMapper("dao"); //设置数据层包名
autoGenerator.setPackageInfo(packageInfo);
//策略设置
StrategyConfig strategyConfig = new StrategyConfig();
strategyConfig.setInclude("tbl_user"); //设置当前参与生成的表名,参数为可变参数
strategyConfig.setTablePrefix("tbl_"); //设置数据库表的前缀名称,模块名 = 数据库表名 - 前缀名 例如: User = tbl_user - tbl_
strategyConfig.setRestControllerStyle(true); //设置是否启用Rest风格
strategyConfig.setVersionFieldName("version"); //设置乐观锁字段名
strategyConfig.setLogicDeleteFieldName("deleted"); //设置逻辑删除字段名
strategyConfig.setEntityLombokModel(true); //设置是否启用lombok
autoGenerator.setStrategy(strategyConfig);
//2.执行生成操作
autoGenerator.execute();
}
}
边栏推荐
- js判断 数组/对象数组 1 是否包含数组/对象数组 2
- SQL question brushing: find the employee number EMP with more than 15 salary records_ No and its corresponding recording times t
- Beginner's Guide to electronic bidding
- Linux redis source code installation
- MySQL stored procedure realizes the creation of a table (copy the structure of the original table and create a new table)
- Intel带你初识视觉识别--OpenVINO
- Day2: 130 questions in three languages
- Univariate function integration 1__ Indefinite integral
- PLATO上线LAAS协议Elephant Swap,用户可借此获得溢价收益
- Digital twin rail transit: "intelligent" monitoring to clear the pain points of urban operation
猜你喜欢

Solid smart contract tutorial (5) -nft auction contract

Intel带你初识视觉识别--OpenVINO

Univariate function integration 1__ Indefinite integral

Spark 3.0 中七个必须知道的 SQL 性能优化

Recommended Spanish translation of Beijing passport

Google Play APK 上传其他国际应用商店

J9数字论:什么因素决定NFT的价值?

Docuware mobile labor solution can help you build a new productivity model: anytime, anywhere, any device

Oozie工作调度

C语言300行代码实现扫雷(可展开+可标记+可更改困难级别)
随机推荐
uniapp movable-view表格缩放过程想保持容器高度不变的解决办法
教你一文解决 js 数字精度丢失问题
Instruction rearrangement, happens before, as if serial
Redis installation, cluster deployment and common tuning
New pseudo personal guide page source code
nep 2022 cat
C language bracket matching (stack bracket matching C language)
Canal real-time parsing MySQL binlog data practice
Docuware mobile labor solution can help you build a new productivity model: anytime, anywhere, any device
mysql分表之后怎么平滑上线?
Digital currency of quantitative transactions - generate foot print factor data
[Jenkins' notes] introduction, free space; Continuous integration of enterprise wechat; Allure reports, continuous integration of email notifications; Build scheduled tasks
Solid smart contract tutorial (5) -nft auction contract
【ManageEngine】局域网监控软件是什么,有什么作用
Intel introduces you to visual recognition -- openvino
Flash reports an error: type object 'news' has no attribute' query 'the view name is duplicate with the model name
Canal实时解析mysql binlog数据实战
Connect with Alipay payment
量化交易之数字货币篇 - 生成foot print因子数据
转:认知亚文化