MyBatis-Plus通過插件將數(shù)據(jù)庫表生成Entiry,Mapper.xml,Mapper.class的方式
創(chuàng)建maven項目,修改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>
<!-- 輸出目錄(默認java.io.tmpdir) -->
<outputDir>${configuration.outputDir}</outputDir>
<!-- 是否覆蓋同名文件(默認false) -->
<fileOverride>true</fileOverride>
<!-- mapper.xml 中添加二級緩存配置(默認true) -->
<enableCache>true</enableCache>
<!-- 開發(fā)者名稱 -->
<author>ZuoQuan Tu</author>
<!-- 是否開啟 ActiveRecord 模式(默認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(默認),
underline_to_camel,(下劃線轉(zhuǎn)駝峰)
remove_prefix,(去除第一個下劃線的前部分,后面保持不變)
remove_prefix_and_camel(去除第一個下劃線的前部分,后面轉(zhuǎn)駝峰) -->
<naming>underline_to_camel</naming>
<!-- 表前綴 -->
<!--<tablePrefix>bmd_</tablePrefix>-->
<!--Entity中的ID生成策略(默認 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等就需要寫全包名(默認com.baomidou) -->
<parent>${packageInfo.parent}</parent>
<!--service包名(默認service)-->
<service>service</service>
<!--serviceImpl包名(默認service.impl)-->
<serviceImpl>service.impl</serviceImpl>
<!--entity包名(默認entity)-->
<entity>entity</entity>
<!--mapper包名(默認mapper)-->
<mapper>mapper</mapper>
<!--xml包名(默認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>
項目運行步驟
A、修改pom.xml中的properties中的各各參數(shù)的值,以適應自己項目中的配置
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)容對大家的學習或者工作具有一定的參考學習價值,謝謝大家對腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請查看下面相關(guān)鏈接
相關(guān)文章
解決Spring事務@Transactional多層嵌套失效問題
在使用Spring進行事務管理時,可能會遇到事務失效的問題,主要原因包括數(shù)據(jù)庫不支持事務、方法訪問級別不是public、未被Spring管理的Bean、當前類的方法內(nèi)部調(diào)用以及配置的事務傳播性不當?shù)?解決事務失效的方法有使用聲明式事務處理采用合適的事務傳播行為2024-11-11
JavaWeb之Servlet注冊頁面的實現(xiàn)示例
注冊頁面是很多網(wǎng)站都會是使用的到,本文主要介紹了JavaWeb之Servlet注冊頁面的實現(xiàn)示例,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-04-04
繼承WebMvcConfigurationSupport后自動配置不生效及如何配置攔截器
這篇文章主要介紹了繼承WebMvcConfigurationSupport后自動配置不生效及如何配置攔截器,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-11-11
Mybatis框架之代理模式(Proxy Pattern)的實現(xiàn)
本文主要介紹了MyBatis框架中使用代理模式ProxyPattern的原理和實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2024-11-11
java Comparator.comparing排序使用示例
本文主要介紹了java Comparator.comparing排序使用示例,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-10-10

