还在用 JPA Hibernate 吗,试试 mybatis-mp 的一款绝顶好用 ORM 的框架!!!

来源: 投稿
作者: Ai东
2024-06-14 09:42:00

官方文档:http://mybatis-mp.cn

mybatis-mp 是一款超级好用ORM框架,它不是mybatis-plus;设计简单、 使用灵活、快捷、扩展性超强

JPA Hibernate JdbcTempte 等要么太死 太难 太呆;稍微复杂一点就需要拼sql 好累!!!

所以为什么不来试试 mybatis-mp;我只能说这太好用了,不信的 可以自己去试试,反正免费的!!!

1 单表:

//单条

SysUser sysUser=QueryChain.of(sysUserMapper)
        .like(SysUser::getName,"xx")
        .limit(1)
        .get()

//list

List<SysUser> list=QueryChain.of(sysUserMapper)
        .like(SysUser::getName,"xx")
        .list()


//分页

Pager<SysUser> page=QueryChain.of(sysUserMapper)
        .like(SysUser::getName,"xx")
        .paging(Pager.of(1,20))

2 连表:

//VO

@Data
@ResultEntity(SysUser.class)
public class SysUserRoleVo {

    private Integer id;

    private String userName;

    @ResultEntityField(target = SysUser.class, property = "password")
    private String pwd;


    @NestedResultEntity(target = SysRole.class)
    private SysRole role;
}


//单条


SysUserVO sysUserVO=QueryChain.of(sysUserMapper)
        .select(SysUserVO.class)
        .from(SysUser.class)
        .join(SysUser.class, SysRole.class, on -> on.eq(SysUser::getRoleId, SysRole::getId)
        .like(SysUser::getName,"xx")
        .limit(1)
        .returnType(SysUserVO.class)
        .get()


//list

List<SysUserVO> list=QueryChain.of(sysUserMapper)
        .select(SysUserVO.class)
        .from(SysUser.class)
        .join(SysUser.class, SysRole.class, on -> on.eq(SysUser::getRoleId, SysRole::getId)
        .like(SysUser::getName,"xx")
        .returnType(SysUserVO.class)
        .list()

//分页

Pager<SysUserVO> page=QueryChain.of(sysUserMapper)
        .select(SysUserVO.class)
        .from(SysUser.class)
        .join(SysUser.class, SysRole.class, on -> on.eq(SysUser::getRoleId, SysRole::getId)
        .like(SysUser::getName,"xx")
        .returnType(SysUserVO.class)
        .paging(Pager.of(1,20))

复杂定制

展示 窗口函数能力 实现 ORM + SQL模板的厉害



SysUserRoleAutoSelectVo vo = QueryChain.of(sysUserMapper)
        .select(SysUserRoleAutoSelectVo.class)
        .selectWithFun(SysRole::getId, c -> CmdTemplate.create(" RANK() OVER( ORDER BY {0}) ", c).as("RANK2"))
        .from(SysUser.class)
        .join(SysUser.class, SysRole.class)
        .returnType(SysUserRoleAutoSelectVo.class)
        .orderBy(SysUser::getId)
        .limit(1)
        .get();

轻轻松松 简简单单 帮你迅速开发;还有很多很好的功能和特性,请前往官网查看 :http://mybatis-mp.cn

mybatis-mp 可以说 没有构建不出来的 sql 欢迎体验:http://mybatis-mp.cn

展开阅读全文
点击加入讨论🔥(3) 发布并加入讨论🔥
本篇精彩评论
还在用 JPA Hibernate 吗,试试 mybatis-mp 的一款绝顶好用 ORM 的框架!!!
2024-06-14 10:25
1
举报
3 评论
1 收藏
分享
返回顶部
顶部