分佈式架構之 MP

一、MyBatis-Plus 是什麼?

MyBatis-Plus(簡稱 MP)是一個 MyBatis 的增強工具,在 MyBatis 的基礎上只做增強不做改變,爲簡化開發、提高效率而生。

二、MyBatis-Plus 所期望的願景是什麼?

我們的願景是成爲 MyBatis 最好的搭檔,就像 魂鬥羅 中的 1P、2P,基友搭配,效率翻倍。

三、MyBatis-Plus 的特性有哪些?

四、MyBatis-Plus 目前支持哪些數據庫?

五、MyBatis-Plus 的框架結構是怎樣的?

六、爲什麼使用 MyBatis-Plus?

這裏引用我曾經寫過的博文來回答:
關於爲什麼要使用 MyBatis-Plus 這個問題,我結合個人的使用經驗,從代碼生成器、易學性、應用性、安全性角度分析,歸納如下幾個方面?

七、MyBatis-Plus 與 MyBatis 有什麼不同?

相同點:

它們都是用於持久層開發 (DAO 層,又稱數據訪問層), 一般都用於常用的 SSM 框架或者是 SpringBoot 構建微服務,關於 SSM 框架實戰和 SpringBoot 集成構建微服務,後面會講到的。

不同點:

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
    <groupId>com.yc.framework</groupId>
    <artifactId>yc-common-mp</artifactId>
</dependency>

2. 配置文件

# Spring
spring:
  application:
    # 應用名稱
    name: yc-example-mp
  datasource:
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://127.0.0.1:3306/yc-framework?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
    username: user_xxx
    password: xxxxx
# mybatis-plus相關配置
mybatis-plus:
  # xml掃描,多個目錄用逗號或者分號分隔(告訴 Mapper 所對應的 XML 文件位置)
  mapper-locations: classpath:mapper/*.xml

3. 對應的啓動類添加如下註解

@MapperScan("xxxx.xxxx.xxxx")

相關示例參考如下:
https://github.com/developers-youcong/yc-framework/tree/main/yc-auth

https://github.com/developers-youcong/yc-framework/tree/main/yc-modules/yc-admin

以上源代碼均已開源,開源不易,如果對你有幫助,不妨給個 star!!!

YC-Framework 官網:
https://framework.youcongtech.com/

YC-Framework Github 源代碼:
https://github.com/developers-youcong/yc-framework

YC-Framework Gitee 源代碼:
https://gitee.com/developers-youcong/yc-framework

本文由 Readfog 進行 AMP 轉碼,版權歸原作者所有。
來源https://mp.weixin.qq.com/s/QXcvUDF-5geDeSJIiCx2NA