目录
xxxDO=实体类, 相当于:
select name, id from xxx group by name where delete_flag = 0 and status = 0
LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery();
queryWrapper.select(xxxDO::getName, DO::getId);
queryWrapper.eq(xxxDO::getDeleteFlag, 0);
queryWrapper.eq(xxxDO::getStatus, 0);
queryWrapper.groupBy(xxxDO::getName);
List list = getBaseMapper().selectList(queryWrapper);
xxxDO=实体类,相当于:
select sex, ifnull(count(id), 0) AS num, CASE WHEN sex = 1 THEN ‘男’ WHEN sex = 0 THEN ‘女’ ELSE ‘未知’ END AS sexStr from xxx group by sexwherestatus = 0
LambdaQueryWrapper queryWrapper = new QueryWrapper()
.select("sex, ifnull(count(id), 0) AS num, CASE WHEN sex = 1 THEN '男' WHEN sex = 0 THEN '女' ELSE '未知' END AS sexStr").lambda();
queryWrapper.eq(xxxDO::getStatus, 0);
queryWrapper.groupBy(xxxDO::getSex);
List
返回结果是一个list, 里面的map key是查询的属性名, value是参数值。伪代码示意:
list[0]
map[0] (sex=1)
map[1] (num=5)
map[2] (sexStr=男)
list[1]
map[0] (sex=1)
map[1] (num=5)
map[2] (sexStr=男)
偶然而发, 记录一下
queryWrapper.apply("INET_ATON(qsip) <= INET_ATON({0})", ipQuery); queryWrapper.apply("INET_ATON(zzip) >= INET_ATON({0})", ipQuery);
- 1
- 2
queryWrapper.last(" order by id asc"); queryWrapper.last("limit 1");
- 1
- 2
// last也可以追加limit 这里用page接口 IPage
buildPage = new Page<>(0, 200); // ServiceImpl的page调用的是baseMapper的selectPage, getBaseMapper().selectPage() IPage page = page(buildPage, queryWrapper);
- 1
- 2
- 3
- 4
- 5
sql打印
先自我介绍一下,小编13年上师交大毕业,曾经在小公司待过,去过华为OPPO等大厂,18年进入阿里,直到现在。深知大多数初中级java工程师,想要升技能,往往是需要自己摸索成长或是报班学习,但对于培训机构动则近万元的学费,着实压力不小。自己不成体系的自学效率很低又漫长,而且容易碰到天花板技术停止不前。因此我收集了一份《java开发全套学习资料》送给大家,初衷也很简单,就是希望帮助到想自学又不知道该从何学起的朋友,同时减轻大家的负担。添加下方名片,即可获取全套学习资料哦