flying MyBatis 的扩展插件

开源网站开源项目 24-04-08 13:11:13

flying 是一个可以极大增加 mybatis 开发速度的插件组,它提供了一种全新的操作数据的方式,希望能对您有所帮助。

flying 主要特点:

以前我们在 mapper.xml 中要写很复杂的 sql 语句,但现在在 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 就完全明白您的数据结构和您想做的事情了。接下来您增删改查这个实体就会变得非常简单:

    /* 新增 */    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 代表相同的业务数据 */        /* 按年龄查询,这里忽略了姓名 */    Account accountC2 = new Account();    accountC2.setAge(18);    Account account2 = accountService.selectOne(accountC2);    /* account2 和 account 代表相同的业务数据 */        /* 按姓名和年龄查询 */    Account accountC3 = new Account();    accountC3.setName("ann");    accountC3.setAge(18);    Account account3 = accountService.selectOne(accountC3);    /* account3 和 account 代表相同的业务数据 */        /* 修改 */    account.setName("bob");    accountService.update(newAccount);        /* 按主键删除 */    accountService.delete(newAccount);

由于 flying 掌握了您全部的数据结构和实体关系,所以操作数据变得非常简单,您再也不需要定义 “getAccountById、getAccountByName、getAccountByAge” 这样重复性强的方法了,由此带来更大的好处是您的 service 层只需要关注事务方面的逻辑即可,它从低级代码中完全解放了出来。以上只是 flying 功能的冰山一角,其它的功能如多表联查、分页、乐观锁、或逻辑查询、复杂外键关系等 flying 都有简单的解决方案,您可以在https://flyingdoc.gitee.io/中进行查看。

flying 特点总结如下:

数据操作入参和返回类型都是自定义的实体类,完全 no sql 杜绝各种‘’手滑‘’,项目可随意重构。

支持跨表操作和跨数据源操作。

非侵占工作机制,可以和您已有的 mybatis 方法协同工作。

加入了优化过的缓存插件,可以对多数据源环境下flying 方法和传统 mybatis 方法同时进行缓存管理。

可以自定义主键生成器,全面支持或逻辑查询。(初雪版新增特性)

可以在 flying 语句中指定查询的数据库和数据源,达到高性能跨库查询。(阳春版新增特性)

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.10.8.3不再支持不再支持3.4.0、3.4.1、3.4.2、3.4.3、3.4.4、3.4.5、3.4.60.9.30.9.40.9.9

之所以采用分版本发布的方式是因为我们对 mybatis 每个版本的用户都认真负责,力求使您得到 flying 最大的好处。

flying 代码示例:

我们还为您提供了一个快速上手的示例:

最新版本demo:https://gitee.com/limeng32/flying-demo-use-springboot

更多内容请您参见软件文档https://flyingdoc.gitee.io/。

清明 新增内容:

支持复杂的外键关系,如join 的条件是同时满足多个逻辑判断且不仅限于相等

在默认左联接的基础上支持右联接

修正上一版本在高并发场景下 sql 语句有时会混乱的问题

demo 完全由 spring-boot 方式重构

阳春新增内容:

@FieldMapperAnnotation 和 @ConditionMapperAnnotation 增加了 customTypeHandler 属性,其具有最高优先级。

初雪 新增内容:

自定义主键生成器,包括 flying 内置和完全自定义两种形式。

全面支持或逻辑查询,可以用在普通查询和跨表查询中。

@QueryMapperAnnotation 现在可以省略,只要您的某个类既继承实体 pojo 又实现Conditionable 接口 flying 就可以判断出它是相关 pojo 的条件类。

0.9.2 新增内容:

兼容 JPA 中的 @Column、@Id、@Table 标签,这些标签可以和 @FieldMapperAnnotation、@TableMapperAnnotation 协同使用,优先级从高到低为:@Id、@FieldMapperAnnotation 和 @TableMapperAnnotation、@Column 和 @Table。

现在 ignoreTag 对 insert、update、updatePersistent 也会起作用。如果 @Column 中设置 insertable = false 和 updateable = false,会在新增和修改时起到永久性忽略的作用。

[flying MyBatis 的扩展插件]相关推荐

Osiris 分布式论坛程序

Osiris 是一套去中心化的分布式论坛程序。GIT式的内容控制能力和信用的继承功能,让它十分有趣。程序使用 ……...

Yzncms 内容管理系统

Yzncms 内容管理系统

[项目介绍] YznCMS(又名御宅男CMS)是基于最新TP5.1x框架和layui2.5x的后台管理系统。创立于2017年初,是……...

今日开源
  1. iMap 基于 Electron 和 Vue 的旅行地图生成工具

    iMap 基于 Electron 和 Vue 的旅行地图生成工具

    iMap是一款跨平台(MacOS,Linux,Windows),基于 Electron 和 Echarts 的旅行地图生成器 下载 MacOSWindowsLinux 启动项目 #installdependenciesyarn#servewithhotreloadatlocalhost:8090yarnrundev#buildforpr……

    开源软件 2024-05-10

  2. Syncope 数字身份管理

    Syncope 数字身份管理

    Apache Syncope 是用在企业环境的数字身份管理,在JEE技术的实施和Apache 2.0许可下发布的开源系统。 Identity management (or IdM) represents the joint result of business process and IT to manage user dat……

    开源软件 2024-05-10

  3. Giraffe 编码动画 GIF 文件

    Giraffe 是 iPhone 的编码动画 GIF 文件,使用的 GIF 编码库是 ANGif(UIImagePixelSource.m 和 ExportViewController.m 文件 ) ANGif 示例 ANGifEncoder*encoder=[[ANGifEncoderalloc]initWithOutputFile:@"myFi……

    开源软件 2024-05-10

返回顶部小火箭