MyBatis-Plus通過插件將數(shù)據(jù)庫表生成Entiry,Mapper.xml,Mapper.class的方式
創(chuàng)建maven項(xiàng)目,修改pom.xml文件,如下:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.xxxx</groupId>
<artifactId>parent-pom</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<groupId>com.xxxx</groupId>
<artifactId>mapper-creator</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<configuration.outputDir>d:\demo-mapper-folder</configuration.outputDir>
<dataSource.url>jdbc:mysql://192.168.18.140:8066/TESTDB?useUnicode=true&characterEncoding=UTF-8</dataSource.url>
<dataSource.username>root</dataSource.username>
<dataSource.password>123456</dataSource.password>
<packageInfo.parent>com.xxxx.demotwo</packageInfo.parent>
</properties>
<build>
<plugins>
<plugin>
<groupId>com.baomidou</groupId>
<artifactId>mybatisplus-maven-plugin</artifactId>
<version>1.0</version>
<configuration>
<!-- 輸出目錄(默認(rèn)java.io.tmpdir) -->
<outputDir>${configuration.outputDir}</outputDir>
<!-- 是否覆蓋同名文件(默認(rèn)false) -->
<fileOverride>true</fileOverride>
<!-- mapper.xml 中添加二級緩存配置(默認(rèn)true) -->
<enableCache>true</enableCache>
<!-- 開發(fā)者名稱 -->
<author>ZuoQuan Tu</author>
<!-- 是否開啟 ActiveRecord 模式(默認(rèn)true) -->
<activeRecord>false</activeRecord>
<!-- 數(shù)據(jù)源配置,( **必配** ) -->
<dataSource>
<driverName>com.mysql.jdbc.Driver</driverName>
<url>${dataSource.url}</url>
<username>${dataSource.username}</username>
<password>${dataSource.password}</password>
</dataSource>
<strategy>
<!-- 字段生成策略,四種類型,從名稱就能看出來含義:
nochange(默認(rèn)),
underline_to_camel,(下劃線轉(zhuǎn)駝峰)
remove_prefix,(去除第一個下劃線的前部分,后面保持不變)
remove_prefix_and_camel(去除第一個下劃線的前部分,后面轉(zhuǎn)駝峰) -->
<naming>underline_to_camel</naming>
<!-- 表前綴 -->
<!--<tablePrefix>bmd_</tablePrefix>-->
<!--Entity中的ID生成策略(默認(rèn) id_worker)-->
<idGenType>uuid</idGenType>
<!--自定義超類-->
<!--<superServiceClass>com.baomidou.base.BaseService</superServiceClass>-->
<!-- 要包含的表 與exclude 二選一配置-->
<!--<include>-->
<!--<property>sec_user</property>-->
<!--<property>table1</property>-->
<!--</include>-->
<!-- 要排除的表 -->
<!--<exclude>-->
<!--<property>schema_version</property>-->
<!--</exclude>-->
</strategy>
<packageInfo>
<!-- 父級包名稱,如果不寫,下面的service等就需要寫全包名(默認(rèn)com.baomidou) -->
<parent>${packageInfo.parent}</parent>
<!--service包名(默認(rèn)service)-->
<service>service</service>
<!--serviceImpl包名(默認(rèn)service.impl)-->
<serviceImpl>service.impl</serviceImpl>
<!--entity包名(默認(rèn)entity)-->
<entity>entity</entity>
<!--mapper包名(默認(rèn)mapper)-->
<mapper>mapper</mapper>
<!--xml包名(默認(rèn)mapper.xml)-->
<xml>mapper</xml>
</packageInfo>
<template>
<!-- 定義controller模板的路徑 -->
<!--<controller>/template/controller1.java.vm</controller>-->
</template>
</configuration>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
項(xiàng)目運(yùn)行步驟
A、修改pom.xml中的properties中的各各參數(shù)的值,以適應(yīng)自己項(xiàng)目中的配置
B、在maven的setting.xml中添加:
<pluginGroups> <pluginGroup>com.baomidou</pluginGroup> </pluginGroups>
C、執(zhí)行以下maven命令:
mvn mp:code
執(zhí)行完成之后,即可看到彈出一個文件夾,里面包含了要生成的表的Entity,mapper,mapper.xml等
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,謝謝大家對腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請查看下面相關(guān)鏈接
相關(guān)文章
SpringBoot項(xiàng)目集成依賴Mybatis步驟
在本篇文章中小編給大家分享了關(guān)于SpringBoot項(xiàng)目如何集成依賴Mybatis的相關(guān)知識點(diǎn)內(nèi)容,有興趣的朋友們學(xué)習(xí)下。2019-06-06
spring-boot實(shí)現(xiàn)增加自定義filter(新)
本篇文章主要介紹了spring-boot實(shí)現(xiàn)增加自定義filter(新),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-05-05
Spring Boot中的 6 種API請求參數(shù)讀取方式示例詳解
使用Spring Boot開發(fā)API的時候,讀取請求參數(shù)是服務(wù)端編碼中最基本的一項(xiàng)操作,Spring Boot中也提供了多種機(jī)制來滿足不同的API設(shè)計要求,這篇文章主要介紹了Spring Boot中的 6 種API請求參數(shù)讀取方式示例詳解,需要的朋友可以參考下2024-05-05
詳解springmvc控制登錄用戶session失效后跳轉(zhuǎn)登錄頁面
本篇文章主要介紹了springmvc控制登錄用戶session失效后跳轉(zhuǎn)登錄頁面,session一旦失效就需要重新登陸,有興趣的同學(xué)可以了解一下。2017-01-01
JAVA設(shè)計模式零基礎(chǔ)解析之單例模式的八種方式
設(shè)計模式(Design pattern)是一套被反復(fù)使用、多數(shù)人知曉的、經(jīng)過分類編目的、代碼設(shè)計經(jīng)驗(yàn)的總結(jié)。使用設(shè)計模式是為了可重用代碼、讓代碼更容易被他人理解、保證代碼可靠性2021-10-10
Java實(shí)戰(zhàn)項(xiàng)目之斗地主和斗牛游戲的實(shí)現(xiàn)
讀萬卷書不如行萬里路,只學(xué)書上的理論是遠(yuǎn)遠(yuǎn)不夠的,只有在實(shí)戰(zhàn)中才能獲得能力的提升,本篇文章手把手帶你用Java實(shí)現(xiàn)一個斗地主和一個斗牛游戲,大家可以在過程中查缺補(bǔ)漏,提升水平2021-11-11

