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 數據庫
相關文章:
主站蜘蛛池模板: 黄色大片av | 国产精品日韩欧美 | 在线午夜视频 | 夜间福利视频 | 免费观看黄色大片 | 久久午夜视频 | 欧美黑人一区二区三区 | 一区二区三区中文字幕 | 成人高清在线 | 亚洲资源站 | 黄色一级片免费 | 久久九九视频 | 一级片在线免费观看 | 人人综合网 | 在线午夜视频 | 99在线视频免费观看 | av久久久 | 日韩在线视频免费观看 | 国产精品国产三级国产专区53 | 国产精品一区二区三区免费 | av网站免费在线观看 | 男女操网站 | 欧美一区二区三区在线视频 | 韩日一级片 | 99视频 | 97精品国产97久久久久久免费 | 中文字幕偷拍 | 美女久久久 | 午夜天堂在线 | 国产精品尤物 | 日韩一级av毛片 | 97在线视频观看 | 日本特级黄色片 | 国产一区免费视频 | 免费看黄网 | 亚洲精品一区二区三 | 天天干夜夜撸 | 日本不卡一区 | 91精品国产日韩91久久久久久 | 182tv午夜 | 国产三级午夜理伦三级 |