av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

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

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

瀏覽:44日期: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 最詳細使用方法

運行輸入表面就可以了?。。。?/p>

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

標簽: Mybatis 數據庫
相關文章:
主站蜘蛛池模板: 草久久 | 久久久久久成人网 | 在线观看成年视频 | 成人免费在线观看视频 | 自拍第一页| 国产传媒视频在线观看 | 精品在线观看入口 | 亚洲三区在线观看 | 超碰国产在线 | 日韩中文字幕网 | 亚洲美女一区二区三区 | 黄色在线免费观看视频网站 | 国产一二三区在线 | 一区二区三区视频免费看 | 色站综合 | 日韩欧美一区二区三区免费观看 | 欧美成人手机在线 | 久久国产电影 | 99国产精品久久久 | 麻豆国产一区二区三区四区 | 欧美精品成人一区二区三区四区 | 久在线观看 | 国产ts人妖一区二区三区 | 免费av在线| 久久99精品久久久久蜜桃tv | 色婷婷综合久久久中文字幕 | 天天干天天草 | av在线免费观看网站 | 日本在线播放一区二区 | 欧美大片黄| 日韩国产在线 | 久久成人午夜 | 久热久热| av资源中文在线 | 激情五月婷婷综合 | 日韩欧美网 | 99久久国产综合精品麻豆 | 久久精彩 | 久久久久久高潮国产精品视 | 亚洲欧美高清 | 国产精品久久久久久婷婷天堂 |