为什么推荐使用 mybatis-mp 框架?

来源: 投稿
作者: Ai东
2024-06-07 11:15:00

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

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))

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

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

展开阅读全文
点击加入讨论🔥(7) 发布并加入讨论🔥
本篇精彩评论
mybatis-mp 能帮你解决你在其他orm框架里所有的痛点,不信的评论区见!!!
2024-06-07 11:21
1
举报
7 评论
2 收藏
分享
返回顶部
顶部