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

MyBatis Flex全解析

 更新時間:2025年12月19日 11:59:33   作者:月軒居士  
MyBatis-Flex是一個輕量高效的MyBatis增強框架,具有極高性能和靈活性,MyBatis-Flex 能夠極大地提高我們的開發(fā)效率和開發(fā)體驗,讓我們有更多的時間專注于自己的事情,本文給大家介紹MyBatis Flex全解析,感興趣的朋友跟隨小編一起看看吧

Mybatis-Flex 是一個優(yōu)雅的 Mybatis 增強框架,它非常輕量、同時擁有極高的性能與靈活性。我們可以輕松的使用 Mybaits-Flex 鏈接任何數(shù)據(jù)庫,其內(nèi)置的 QueryWrapper^亮點 幫助我們極大的減少了 SQL 編寫的工作的同時,減少出錯的可能性。

總而言之,MyBatis-Flex 能夠極大地提高我們的開發(fā)效率和開發(fā)體驗,讓我們有更多的時間專注于自己的事情。

Mybatis-Flex的特點

輕量

除了 MyBatis,沒有任何第三方依賴輕依賴、沒有任何攔截器,其原理是通過 SqlProvider 的方式實現(xiàn)的輕實現(xiàn)。同時,在執(zhí)行的過程中,沒有任何的 Sql 解析(Parse)輕運行。這帶來了幾個好處:

1、極高的性能;

2、極易對代碼進行跟蹤和調(diào)試;

3、把控性更高。

如果你近期準備面試跳槽,建議在ddkk.com在線刷題,涵蓋 一萬+ 道 Java 面試題,幾乎覆蓋了所有主流技術(shù)面試題,還有市面上最全的技術(shù)五百套,精品系列教程,免費提供。

靈活

支持 Entity 的增刪改查、以及分頁查詢的同時,Mybatis-Flex 提供了 Db + Row^靈活 工具,可以無需實體類對數(shù)據(jù)庫進行增刪改查以及分頁查詢。與此同時,Mybatis-Flex 內(nèi)置的 QueryWrapper^靈活 可以輕易的幫助我們實現(xiàn) 多表查詢、鏈接查詢、子查詢 等等常見的 SQL 場景。

強大

支持任意關(guān)系型數(shù)據(jù)庫,還可以通過方言持續(xù)擴展,同時支持 多(復(fù)合)主鍵、邏輯刪除、樂觀鎖配置、數(shù)據(jù)脫敏、數(shù)據(jù)審計、 數(shù)據(jù)填充 等等功能。

Mybatis-Flex和同類框架對比

1)功能對比

2)性能對比

  • MyBatis-Flex 的查詢單條數(shù)據(jù)的速度,大概是 MyBatis-Plus 的 5 ~ 10+ 倍。
  • MyBatis-Flex 的查詢 10 條數(shù)據(jù)的速度,大概是 MyBatis-Plus 的 5~10 倍左右。
  • Mybatis-Flex 的分頁查詢速度,大概是 Mybatis-Plus 的 5~10 倍左右。
  • Mybatis-Flex 的數(shù)據(jù)更新速度,大概是 MyBatis-Plus 的 5~10+ 倍。

Mybatis-Flex支持的數(shù)據(jù)庫類型

數(shù)據(jù)庫描述
mysqlMySQL 數(shù)據(jù)庫
mariadbMariaDB 數(shù)據(jù)庫
oracleOracle11g 及以下數(shù)據(jù)庫
oracle12cOracle12c 及以上數(shù)據(jù)庫
db2DB2 數(shù)據(jù)庫
hsqlHSQL 數(shù)據(jù)庫
sqliteSQLite 數(shù)據(jù)庫
postgresqlPostgreSQL 數(shù)據(jù)庫
sqlserver2005SQLServer2005 數(shù)據(jù)庫
sqlserverSQLServer 數(shù)據(jù)庫
dm達夢數(shù)據(jù)庫
xugu虛谷數(shù)據(jù)庫
kingbasees人大金倉數(shù)據(jù)庫
phoenixPhoenix HBase 數(shù)據(jù)庫
gaussGauss 數(shù)據(jù)庫
clickhouseClickHouse 數(shù)據(jù)庫
gbase南大通用(華庫)數(shù)據(jù)庫
gbase-8s南大通用數(shù)據(jù)庫 GBase 8s
oscar神通數(shù)據(jù)庫
sybaseSybase ASE 數(shù)據(jù)庫
OceanBaseOceanBase 數(shù)據(jù)庫
FirebirdFirebird 數(shù)據(jù)庫
derbyDerby 數(shù)據(jù)庫
highgo瀚高數(shù)據(jù)庫
cubridCUBRID 數(shù)據(jù)庫
goldilocksGOLDILOCKS 數(shù)據(jù)庫
csiidbCSIIDB 數(shù)據(jù)庫
hanaSAP HANA 數(shù)據(jù)庫
impalalmpala 數(shù)據(jù)庫
verticaVertica 數(shù)據(jù)庫
xcloud行云數(shù)據(jù)庫
redshift亞馬遜 redshift 數(shù)據(jù)庫
openGauss華為 openGauss 數(shù)據(jù)庫
TDengineTDengine 數(shù)據(jù)庫
informixInformix 數(shù)據(jù)庫
greenplumGreenplum 數(shù)據(jù)庫
uxdb優(yōu)炫數(shù)據(jù)庫

快速開始

第 1 步:創(chuàng)建數(shù)據(jù)庫表

CREATE TABLE IF NOT EXISTS`user_info`
(
    `id`        INTEGER PRIMARY KEY auto_increment,
    `user_name`VARCHAR(100),
    `age`       INTEGER,
    `birthday`  DATETIME
);
INSERTINTO tb_account(id, user_name, age, birthday)
VALUES(1, '張三', 18, '2020-01-11'),
       (2, '李四', 19, '2021-03-21');

第 2 步:創(chuàng)建 Spring Boot 項目,并添加 Maven 依賴

tips:可以使用 Spring Initializer 快速初始化一個 Spring Boot 工程。

<dependencies>
    <dependency>
        <groupId>com.mybatis-flex</groupId>
        <artifactId>mybatis-flex-spring-boot-starter</artifactId>
        <version>1.5.3</version>
    </dependency>
    <dependency>
        <groupId>com.mysql</groupId>
        <artifactId>mysql-connector-j</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>com.zaxxer</groupId>
        <artifactId>HikariCP</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

第 3 步:對 Spring Boot 項目進行配置

在 application.yml 中配置數(shù)據(jù)源:

# DataSource Config
spring:
  datasource:
    url:jdbc:mysql://localhost:3306/flex_test
    username:root
    password:12345678

在 Spring Boot 啟動類中添加 @MapperScan 注解,掃描 Mapper 文件夾:

@SpringBootApplication
@MapperScan("com.mybatisflex.test.mapper")
publicclassMybatisFlexTestApplication{
    publicstaticvoidmain(String[] args){
        SpringApplication.run(MybatisFlexTestApplication.class, args);
    }
}

第 4 步:編寫實體類和 Mapper 接口

這里使用了 Lombok 來簡化代碼。

@Data
@Table("user_info")
public class UserInfo{
    @Id(keyType = KeyType.Auto)
    private Long id;
    private String userName;
    private Integer age;
    private Date birthday;
}
  • 使用 @Table("tb_account") 設(shè)置實體類與表名的映射關(guān)系
  • 使用 @Id(keyType = KeyType.Auto) 標(biāo)識主鍵為自增

Mapper 接口繼承 BaseMapper 接口:

public interface UserInfoMapperex tends BaseMapper<UserInfo> {
}

這部分也可以使用 MyBatis-Flex 的代碼生成器來生成。

第 5 步:開始使用

添加測試類,進行功能測試:

import static com.mybatisflex.test.entity.table.UserInfo;
@SpringBootTest
class MybatisFlexTestApplicationTests{
    @Autowired
    private AccountMapper accountMapper;
    @Test
    voidcontextLoads(){
        QueryWrapper queryWrapper = QueryWrapper.create()
                .select()
                .where(ACCOUNT.AGE.eq(18));
        Account account = accountMapper.selectOneByQuery(queryWrapper);
        System.out.println(account);
    }
}

控制臺輸出:

UserInfo(id=1, userName=張三, age=18, birthday=Sat Jan 1100:00:00 CST 2020)

上面的示例 中, UserInfo為MyBatis-Flex通過API自動生成,只需通過靜態(tài)導(dǎo)入即可,無需手動編碼。

整體來講,這個框架是Mybatis的增強版,幾乎集成了mybatis plus、jooq、fluent mybatis的所有優(yōu)點。

到此這篇關(guān)于MyBatis Flex全解析的文章就介紹到這了,更多相關(guān)MyBatis Flex詳解內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論

从化市| 定安县| 香港 | 麦盖提县| 罗甸县| 永嘉县| 娱乐| 准格尔旗| 清水河县| 云和县| 遵化市| 陕西省| 铁岭市| 阜新市| 青川县| 西乌珠穆沁旗| 鄄城县| 南漳县| 高尔夫| 电白县| 行唐县| 景洪市| 扶绥县| 开原市| 隆回县| 荃湾区| 南雄市| 榕江县| 温泉县| 启东市| 黎川县| 六盘水市| 博野县| 榆树市| 江源县| 兰溪市| 四会市| 连平县| 栾川县| 榕江县| 西林县|