色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

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

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

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

AutoGenerator 是 MyBatis-Plus 的代碼生成器,通過 AutoGenerator 可以快速生成 Entity、Mapper、Mapper XML、Service、Controller 等各個模塊的代碼,極大的提升了開發效率。可以通過模版等一系列的方式來生成代碼,⚠️這個比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);// 數據源配置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<>();// 自定義配置會被優先輸出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 下面內容修改, // 放置自己項目的 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內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Mybatis 數據庫
相關文章:
主站蜘蛛池模板: 夜色亚洲 | 国产三级香港三韩国三级 | 手机看片1024欧美日韩你懂的 | 国产碰碰 | 亚洲aⅴ在线| 99热久久精品国产 | 韩国一级淫片视频免费播放 | 日本三级欧美三级 | 国产精选莉莉私人影院 | 草草影院ccyy国产日本欧美 | 97视频在线观看免费 | 一a一级片 | 一级特黄一欧美俄罗斯毛片 | 国产手机精品视频 | 毛片成人| 黄黄的网站在线观看 | 欧美日韩精品高清一区二区 | 亚洲精品二区 | 特级a欧美做爰片毛片 | 国产亚洲女在线精品 | 欧美一级一毛片 | 久久精品网站免费观看调教 | 国产精品理论片在线观看 | 国产三a级日本三级日产三级 | 国产精品久久久久久影院 | 夜色福利久久久久久777777 | 国产在线播放免费 | 中文字幕一区视频一线 | 国产成人久久精品区一区二区 | 欧美日韩中文国产一区二区三区 | 亚洲综合久久1区2区3区 | 波多野结衣一区二区 三区 波多野结衣一区二区三区88 | 中文成人在线视频 | 亚洲精品一区二三区在线观看 | 91av爱爱| 99久久精品国产亚洲 | 草草影院永久在线观看 | avwww在线| 99精品在线看 | 一区三区三区不卡 | 国产成人综合在线视频 |