我是靠谱客的博主 顺心奇迹,这篇文章主要介绍sql中mybatis与mybatisplus结合写法,现在分享给大家,希望可以做个参考。

随着mybatisplus的广泛应用,mybatisplus确实比mybatis更加的方便,但是有时候根据业务的需求也要使用mybatis。

  • List item

业务层写法:

复制代码
1
2
3
4
5
6
7
8
9
10
11
QueryWrapper<SysCompany> wrapper = new QueryWrapper<>(); wrapper.and(StringUtils.isNotBlank(query.getKeyword()), wra -> wra.like("company_id", query.getKeyword()).or().like("company_name", query.getKeyword())); wrapper.eq(StringUtils.isNotEmpty(query.getCompanyType()), "company_type", query.getCompanyType()); wrapper.eq(StringUtils.isNotEmpty(query.getAuthStatus()), "auth_status", query.getAuthStatus()); wrapper.eq(query.getFrozen() != null, "frozen", query.getFrozen()); wrapper.orderByDesc("auth_status2","sc.gmt_modified"); IPage<ResCompany> page = sysCompanyMapper.selectCustomPage(new Page<>(pg.getCurrent(), pg.getSize()), wrapper); return PageVO.to(page, ResCompany.class);
  • List item

mapper层

复制代码
1
2
3
IPage<ResCompany> selectCustomPage(@Param("pg") Page<ResCompany> pg, @Param("ew") QueryWrapper<SysCompany> wrapper);

这里注意一定需要使用ew

  • List item

xml层

复制代码
1
2
3
4
5
6
7
SELECT *, (SELECT member_id FROM sys_company_member_relation WHERE company_role = 0 AND company_id = sc.company_id limit 1) AS admin_account, (SELECT COUNT(1) FROM sys_company_auth WHERE company_id = sc.company_id AND auth_status = '2') AS auth_status2 FROM sys_company sc ${ew.customSqlSegment}

最后

以上就是顺心奇迹最近收集整理的关于sql中mybatis与mybatisplus结合写法的全部内容,更多相关sql中mybatis与mybatisplus结合写法内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(57)

评论列表共有 0 条评论

立即
投稿
返回
顶部