久久福利_99r_国产日韩在线视频_直接看av的网站_中文欧美日韩_久久一

您的位置:首頁技術文章
文章詳情頁

Mybatis-Plus-AutoGenerator 最詳細使用方法

瀏覽:42日期:2023-10-24 10:10:38

AutoGenerator 是 MyBatis-Plus 的代碼生成器,通過 AutoGenerator 可以快速生成 Entity、Mapper、Mapper XML、Service、Controller 等各個模塊的代碼,極大的提升了開發(fā)效率。可以通過模版等一系列的方式來生成代碼,⚠️這個比Mybatis-Generator的更加強大,純java代碼。。官方地址:https://mp.baomidou.com/guide/generator.html

package com.cikers.ps; import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException;import com.baomidou.mybatisplus.core.toolkit.StringPool;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 org.apache.commons.lang3.StringUtils; import java.util.ArrayList;import java.util.List;import java.util.Scanner; public class MysqlGenerator {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 = '/Users/syk/Documents/*/*/';gc.setOutputDir(projectPath + '/src/main/java');gc.setAuthor('syk');gc.setOpen(false);gc.setBaseResultMap(true);gc.setBaseColumnList(true);//gc.setControllerName('SSSSScontroller');// 是否覆蓋已有文件gc.setFileOverride(false);mpg.setGlobalConfig(gc);// 數(shù)據(jù)源配置DataSourceConfig dsc = new DataSourceConfig();dsc.setUrl('jdbc:mysql://******/newstack_db?useUnicode=true&characterEncoding=UTF-8');// dsc.setSchemaName('public');dsc.setDriverName('com.mysql.jdbc.Driver');dsc.setUsername('root');dsc.setPassword('password');mpg.setDataSource(dsc);// 包配置PackageConfig pc = new PackageConfig();//pc.setModuleName(scanner('模塊名'));pc.setParent(null); // 這個地址是生成的配置文件的包路徑pc.setEntity('com.cikers.ps.model.entity');//pc.setController('com.cikers.ps.controller');pc.setMapper('com.cikers.ps.mapper');mpg.setPackageInfo(pc);// 自定義配置InjectionConfig cfg = new InjectionConfig() {@Overridepublic void initMap() {// to do nothing}};// 如果模板引擎是 freemarkerString templatePath = '/templates/mapper.xml.ftl';// 如果模板引擎是 velocity //String templatePath = '/templates/mapper.xml.vm';// 自定義輸出配置List<FileOutConfig> focList = new ArrayList<>();// 自定義配置會被優(yōu)先輸出focList.add(new FileOutConfig(templatePath) {@Overridepublic String outputFile(TableInfo tableInfo) {// 自定義輸出文件名return projectPath + '/src/main/resources/mapper/entity'+ '/' + tableInfo.getEntityName() + 'Mapper' + StringPool.DOT_XML;}});cfg.setFileOutConfigList(focList);mpg.setCfg(cfg);// 配置模板TemplateConfig templateConfig = new TemplateConfig();// //配置自定義輸出模板 // 不需要其他的類型時,直接設置為null就不會成對應的模版了 //templateConfig.setEntity('...'); templateConfig.setService(null); templateConfig.setController(null); templateConfig.setServiceImpl(null);// 自定義模板配置,可以 copy 源碼 mybatis-plus/src/main/resources/templates 下面內(nèi)容修改, // 放置自己項目的 src/main/resources/templates 目錄下, 默認名稱一下可以不配置,也 // 可以自定義模板名稱 只要放到目錄下,名字不變 就會采用這個模版 下面這句有沒有無所謂 // 模版去github上看地址: /**https://github.com/baomidou/mybatis-plus/tree/3.0/mybatis-plus-generator/src/main/resources/templates*/ //templateConfig.setEntity('/templates/entity.java');templateConfig.setXml(null);mpg.setTemplate(templateConfig);// 策略配置StrategyConfig strategy = new StrategyConfig();strategy.setNaming(NamingStrategy.underline_to_camel);strategy.setColumnNaming(NamingStrategy.underline_to_camel);strategy.setSuperEntityClass('com.cikers.ps.model.BaseEntity');strategy.setSuperMapperClass('com.cikers.ps.util.IMapper');strategy.setEntityLombokModel(false);//strategy.setRestControllerStyle(false);//strategy.setSuperControllerClass('com.cikers.ps.controller.MysqlController');strategy.setInclude(scanner('表名'));// 設置繼承的父類字段strategy.setSuperEntityColumns('id','modifiedBy','modifiedOn','createdBy','createdOn');//strategy.setControllerMappingHyphenStyle(true);//strategy.setTablePrefix(pc.getModuleName() + '_');mpg.setStrategy(strategy);mpg.setTemplateEngine(new FreemarkerTemplateEngine());mpg.execute();}}

其中需要的maven依賴

<dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.0-RELEASE</version></dependency><!-- mp自動代碼生成--><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-generator</artifactId><version>3.0.7.1</version></dependency><!-- velocity 模板引擎, 默認 --><dependency><groupId>org.apache.velocity</groupId><artifactId>velocity-engine-core</artifactId><version>2.0</version></dependency> <!-- freemarker 模板引擎 --><dependency><groupId>org.freemarker</groupId><artifactId>freemarker</artifactId><version>2.3.23</version></dependency> <!-- beetl 模板引擎 --><dependency><groupId>com.ibeetl</groupId><artifactId>beetl</artifactId><version>2.2.5</version></dependency>

Mybatis-Plus-AutoGenerator 最詳細使用方法

運行輸入表面就可以了!!!!

到此這篇關于Mybatis-Plus-AutoGenerator 最詳細使用方法的文章就介紹到這了,更多相關Mybatis Plus AutoGenerator內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持好吧啦網(wǎng)!

相關文章:
主站蜘蛛池模板: 久久久久久久影院 | 在线欧美日韩 | 成人精品国产免费网站 | 国产一区91 | 欧美午夜精品久久久久免费视 | 日韩精品一区二区三区第95 | 中文字幕在线观看不卡视频 | 中文字幕免费观看 | 国产一区二区三区 | 日韩亚洲一区二区 | 成人理论片 | 国产精品成人3p一区二区三区 | 日韩成人在线观看 | 欧美日韩综合在线 | www.久草.com| 日韩精品久久久久久 | 久久国产精品99久久久久久老狼 | 成年人在线观看 | 亚州男人天堂 | 一区二区在线播放视频 | 蜜桃视频网站在线观看 | 国产男女视频在线观看 | 欧美成人一区二区三区片免费 | 亚洲福利一区二区 | 日本一二三区在线 | 91精品一区二区三区久久久久 | 超碰在线看 | 夜夜草视频 | 国产一级黄色 | 色欧美片视频在线观看 | 特级理论片 | 激情久久av一区av二区av三区 | 日韩污视频在线观看 | 一区二区三区av | 免费看a| 81精品国产乱码久久久久久 | www中文字幕 | 欧美久久一级特黄毛片 | 五月在线视频 | 国产精品国产精品国产专区不卡 | 亚洲国产精品久久人人爱 |