成人视屏在线观看-国产99精品-国产精品1区2区-欧美一级在线观看-国产一区二区日韩-色九九九

您的位置:首頁技術(shù)文章
文章詳情頁

Mybatis-Plus-AutoGenerator 最詳細(xì)使用方法

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

AutoGenerator 是 MyBatis-Plus 的代碼生成器,通過 AutoGenerator 可以快速生成 Entity、Mapper、Mapper XML、Service、Controller 等各個(gè)模塊的代碼,極大的提升了開發(fā)效率。可以通過模版等一系列的方式來生成代碼,⚠️這個(gè)比Mybatis-Generator的更加強(qiáng)大,純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); // 這個(gè)地址是生成的配置文件的包路徑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();// //配置自定義輸出模板 // 不需要其他的類型時(shí),直接設(shè)置為null就不會成對應(yīng)的模版了 //templateConfig.setEntity('...'); templateConfig.setService(null); templateConfig.setController(null); templateConfig.setServiceImpl(null);// 自定義模板配置,可以 copy 源碼 mybatis-plus/src/main/resources/templates 下面內(nèi)容修改, // 放置自己項(xiàng)目的 src/main/resources/templates 目錄下, 默認(rèn)名稱一下可以不配置,也 // 可以自定義模板名稱 只要放到目錄下,名字不變 就會采用這個(gè)模版 下面這句有沒有無所謂 // 模版去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('表名'));// 設(shè)置繼承的父類字段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 模板引擎, 默認(rèn) --><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 最詳細(xì)使用方法

運(yùn)行輸入表面就可以了!!!!

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

標(biāo)簽: Mybatis 數(shù)據(jù)庫
相關(guān)文章:
主站蜘蛛池模板: 国产精品99久久久久久www | 色久综合网| 亚洲精品第一区二区在线 | 成人欧美一区二区三区 | 手机在线观看a | 男女乱淫真视频免费一级毛片 | 中文字幕在线一区二区三区 | 高清欧美性xxxx成熟 | 女黄人东京手机福利视频 | 在线观看免费为成年视频 | 美国全免费特一级毛片 | 成 人 在 线 免费 8888 www | 99久久免费看国产精品 | 一级久久 | 99视频精品全部在线播放 | baoyu121永久免费网站 | 九九国产 | 2000xxxxav影院| 一级a毛片免费观看 | 久久久久久久久久免免费精品 | 国产精品爱久久久久久久小 | 国产成人香蕉久久久久 | 免费成年人在线视频 | 无圣光福利视频 | 欧美一级视频高清片 | 91精品手机国产露脸 | 一级a毛片免费观看 | 国产精品激情丝袜美女 | 亚州中文 | a级在线观看视频 | 97视频免费播放观看在线视频 | 能在线观看的一区二区三区 | 日韩日韩日韩手机看片自拍 | 精品国产高清久久久久久小说 | 成年人网站在线观看视频 | 特黄特黄黄色大片 | 欧美一区二区三区久久综 | 中文字幕在线观看一区 | 亚洲成a人v大片在线观看 | 日本a级片免费观看 | 欧美日本国产 |