flyingMyBatis 的擴展插件
flying 是一個可以極大增加 mybatis 開發(fā)速度的插件組,它提供了一種全新的操作數(shù)據(jù)的方式,希望能對您有所幫助。
flying 主要特點:
以前我們在 mapper.xml 中要寫很復雜的 sql 語句,但現(xiàn)在在 mapper.xml 中只需這樣:
<select id="select" resultMap="result">
flying#{?}:select
</select>
<select id="selectOne" resultMap="result">
flying:selectOne
</select>
<insert id="insert">
flying:insert
</insert>
<update id="update">
flying:update
</update>
<delete id="delete">
flying:delete
</delete>
再在您的實體類上加上這樣一些標注:
package myPackage;
import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;
@Table(name = "account")
public class Account {
@Id
@Column
private Integer id;
@Column
private java.lang.String name;
@Column
private Integer age;
/* 省略 getter 和 setter */
}
flying 就完全明白您的數(shù)據(jù)結(jié)構(gòu)和您想做的事情了。 接下來您增刪改查這個實體就會變得非常簡單:
/* 新增 */
Account newAccount = new Account();
newAccount.setName("ann");
newAccount.setAge(18);
accountService.insert(newAccount);
/* 按主鍵查詢 */
Account account = accountService.select(newAccount.getId());
/* 按姓名查詢,這里忽略了年齡 */
Account accountC1 = new Account();
accountC1.setName("ann");
Account account1 = accountService.selectOne(accountC1);
/* account1 和 account 代表相同的業(yè)務數(shù)據(jù) */
/* 按年齡查詢,這里忽略了姓名 */
Account accountC2 = new Account();
accountC2.setAge(18);
Account account2 = accountService.selectOne(accountC2);
/* account2 和 account 代表相同的業(yè)務數(shù)據(jù) */
/* 按姓名和年齡查詢 */
Account accountC3 = new Account();
accountC3.setName("ann");
accountC3.setAge(18);
Account account3 = accountService.selectOne(accountC3);
/* account3 和 account 代表相同的業(yè)務數(shù)據(jù) */
/* 修改 */
account.setName("bob");
accountService.update(newAccount);
/* 按主鍵刪除 */
accountService.delete(newAccount);
由于 flying 掌握了您全部的數(shù)據(jù)結(jié)構(gòu)和實體關系,所以操作數(shù)據(jù)變得非常簡單,您再也不需要定義 “getAccountById、getAccountByName、getAccountByAge” 這樣重復性強的方法了,由此帶來更大的好處是您的 service 層只需要關注事務方面的邏輯即可,它從低級代碼中完全解放了出來。以上只是 flying 功能的冰山一角,其它的功能如多表聯(lián)查、分頁、樂觀鎖、或邏輯查詢、復雜外鍵關系等 flying 都有簡單的解決方案,您可以在 https://flyingdoc.gitee.io/ 中進行查看。
flying 特點總結(jié)如下:
- 數(shù)據(jù)操作入?yún)⒑头祷仡愋投际亲远x的實體類,完全 no sql 杜絕各種‘’手滑‘’,項目可隨意重構(gòu)。
-
支持跨表操作和跨數(shù)據(jù)源操作。
-
非侵占工作機制,可以和您已有的 mybatis 方法協(xié)同工作。
-
加入了優(yōu)化過的緩存插件,可以對多數(shù)據(jù)源環(huán)境下 flying 方法和傳統(tǒng) mybatis 方法同時進行緩存管理。
-
可以自定義主鍵生成器,全面支持或邏輯查詢。(初雪版新增特性)
-
可以在 flying 語句中指定查詢的數(shù)據(jù)庫和數(shù)據(jù)源,達到高性能跨庫查詢。(陽春版新增特性)
flying 獲取方式:
flying 的 maven 坐標為:
<groupId>com.github.limeng32</groupId>
<artifactId>mybatis.flying</artifactId>
<version>0.9.9</version>
mybatis 版本與 flying 最新版本 清明 的對應關系見下:
| mybatis 版本 | flying-初雪 | flying-陽春 | flying-清明 |
|---|---|---|---|
| 3.3.0、3.3.1 | 0.8.3 | 不再支持 | 不再支持 |
| 3.4.0、3.4.1、3.4.2、3.4.3、3.4.4、3.4.5、3.4.6 | 0.9.3 | 0.9.4 | 0.9.9 |
之所以采用分版本發(fā)布的方式是因為我們對 mybatis 每個版本的用戶都認真負責,力求使您得到 flying 最大的好處。
flying 代碼示例:
我們還為您提供了一個快速上手的示例:
更多內(nèi)容請您參見軟件文檔 https://flyingdoc.gitee.io/。
清明 新增內(nèi)容:
- 支持復雜的外鍵關系,如 join 的條件是同時滿足多個邏輯判斷且不僅限于相等
- 在默認左聯(lián)接的基礎上支持右聯(lián)接
- 修正上一版本在高并發(fā)場景下 sql 語句有時會混亂的問題
- demo 完全由 spring-boot 方式重構(gòu)
陽春 新增內(nèi)容:
- @FieldMapperAnnotation 和 @ConditionMapperAnnotation 增加了 customTypeHandler 屬性,其具有最高優(yōu)先級。
初雪 新增內(nèi)容:
-
自定義主鍵生成器,包括 flying 內(nèi)置和完全自定義兩種形式。
-
全面支持或邏輯查詢,可以用在普通查詢和跨表查詢中。
-
@QueryMapperAnnotation 現(xiàn)在可以省略,只要您的某個類既繼承實體 pojo 又實現(xiàn) Conditionable 接口 flying 就可以判斷出它是相關 pojo 的條件類。
0.9.2 新增內(nèi)容:
- 兼容 JPA 中的 @Column、@Id、@Table 標簽,這些標簽可以和 @FieldMapperAnnotation、@TableMapperAnnotation 協(xié)同使用,優(yōu)先級從高到低為:@Id、@FieldMapperAnnotation 和 @TableMapperAnnotation、@Column 和 @Table。
-
現(xiàn)在 ignoreTag 對 insert、update、updatePersistent 也會起作用。如果 @Column 中設置 insertable = false 和 updateable = false,會在新增和修改時起到永久性忽略的作用。
