最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時(shí)間:2020年03月25日 14:13:03   作者:sky豫  
這篇文章主要介紹了Mybatis-Plus-AutoGenerator 最詳細(xì)使用方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

AutoGenerator 是 MyBatis-Plus 的代碼生成器,通過(guò) AutoGenerator 可以快速生成 Entity、Mapper、Mapper XML、Service、Controller 等各個(gè)模塊的代碼,極大的提升了開(kāi)發(fā)效率??梢酝ㄟ^(guò)模版等一系列的方式來(lái)生成代碼,⚠️這個(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("請(qǐng)輸入" + tip + ":");
		System.out.println(help.toString());
		if (scanner.hasNext()) {
			String ipt = scanner.next();
			if (StringUtils.isNotEmpty(ipt)) {
				return ipt;
			}
		}
		throw new MybatisPlusException("請(qǐng)輸入正確的" + 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() {
			@Override
			public void initMap() {
				// to do nothing
			}
		};
		
		// 如果模板引擎是 freemarker
		String templatePath = "/templates/mapper.xml.ftl";
		// 如果模板引擎是 velocity
		 //String templatePath = "/templates/mapper.xml.vm";
		
		// 自定義輸出配置
		List<FileOutConfig> focList = new ArrayList<>();
		// 自定義配置會(huì)被優(yōu)先輸出
		focList.add(new FileOutConfig(templatePath) {
			@Override
			public 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就不會(huì)成對(duì)應(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)名稱一下可以不配置,也 
    // 可以自定義模板名稱 只要放到目錄下,名字不變 就會(huì)采用這個(gè)模版 下面這句有沒(méi)有無(wú)所謂
     // 模版去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自動(dòng)代碼生成-->
		<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>

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

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

相關(guān)文章

  • Maven引用自定義jar包方式

    Maven引用自定義jar包方式

    這篇文章主要介紹了Maven引用自定義jar包方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-09-09
  • 淺談Action+Service +Dao 功能

    淺談Action+Service +Dao 功能

    下面小編就為大家?guī)?lái)一篇淺談Action+Service +Dao 功能。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-07-07
  • spring boot 實(shí)現(xiàn)Minio分片上傳的步驟

    spring boot 實(shí)現(xiàn)Minio分片上傳的步驟

    分片上傳,就是將所要上傳的文件,按照一定的大小,將整個(gè)文件分隔成多個(gè)數(shù)據(jù)塊來(lái)進(jìn)行分別上傳,上傳完之后再由服務(wù)端對(duì)所有上傳的文件進(jìn)行匯總整合成原始的文件,本文給大家介紹spring boot 實(shí)現(xiàn)Minio分片上傳的步驟,感興趣的朋友跟隨小編一起看看吧
    2023-10-10
  • SpringBoot集成H2內(nèi)存數(shù)據(jù)庫(kù)的方法

    SpringBoot集成H2內(nèi)存數(shù)據(jù)庫(kù)的方法

    H2是Thomas Mueller提供的一個(gè)開(kāi)源的、純java實(shí)現(xiàn)的關(guān)系數(shù)據(jù)庫(kù)。本文主要介紹了SpringBoot集成H2內(nèi)存數(shù)據(jù)庫(kù),具有一定的參考價(jià)值,感興趣的可以了解一下
    2021-09-09
  • Java編程Webservice指定超時(shí)時(shí)間代碼詳解

    Java編程Webservice指定超時(shí)時(shí)間代碼詳解

    這篇文章主要介紹了Java編程Webservice指定超時(shí)時(shí)間代碼詳解,簡(jiǎn)單介紹了webservice,然后分享了通過(guò)使用JDK對(duì)Webservice的支持進(jìn)行Webservice調(diào)用實(shí)現(xiàn)指定超時(shí)時(shí)間完整示例,具有一定借鑒價(jià)值,需要的朋友可以參考下。
    2017-11-11
  • 基于jenkins發(fā)布編譯后的class文件

    基于jenkins發(fā)布編譯后的class文件

    這篇文章主要介紹了基于jenkins發(fā)布編譯后的class文件,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-07-07
  • spring cloud如何修復(fù)zuul跨域配置異常的問(wèn)題

    spring cloud如何修復(fù)zuul跨域配置異常的問(wèn)題

    最近的開(kāi)發(fā)過(guò)程中,使用spring集成了spring-cloud-zuul,在配置zuul跨域的時(shí)候遇到了問(wèn)題,下面這篇文章主要給大家介紹了關(guān)于spring cloud如何修復(fù)zuul跨域配置異常的問(wèn)題,需要的朋友可以參考借鑒,下面來(lái)一起看看吧。
    2017-09-09
  • SpringBoot實(shí)現(xiàn)物品點(diǎn)贊功能

    SpringBoot實(shí)現(xiàn)物品點(diǎn)贊功能

    這篇文章主要介紹了SpringBoot物品點(diǎn)贊功能實(shí)現(xiàn),本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-04-04
  • 使用監(jiān)聽(tīng)器對(duì)Spring bean id進(jìn)行唯一校驗(yàn)過(guò)程解析

    使用監(jiān)聽(tīng)器對(duì)Spring bean id進(jìn)行唯一校驗(yàn)過(guò)程解析

    這篇文章主要介紹了使用監(jiān)聽(tīng)器對(duì)Spring bean id進(jìn)行唯一校驗(yàn)過(guò)程解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-08-08
  • Springboot遷移到Micronaut實(shí)現(xiàn)過(guò)程詳解

    Springboot遷移到Micronaut實(shí)現(xiàn)過(guò)程詳解

    這篇文章主要為大家?介紹了Springboot遷移到Micronaut實(shí)現(xiàn)過(guò)程詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-05-05

最新評(píng)論

许昌市| 宁城县| 湘潭市| 大余县| 许昌市| 巴林左旗| 巴林左旗| 乡城县| 罗定市| 武强县| 安多县| 蒙城县| 黄平县| 五大连池市| 牟定县| 开封县| 北流市| 蒙山县| 花莲市| 鄂温| 建平县| 金山区| 吉木乃县| 牙克石市| 正定县| 子洲县| 平昌县| 聂荣县| 太湖县| 石景山区| 佛坪县| 公安县| 和政县| 紫阳县| 鱼台县| 芷江| 南乐县| 双牌县| 师宗县| 溆浦县| 元阳县|