1、select使用count函数
QueryWrapper<GeoAssoc> countWrapper = new QueryWrapper<>();
countWrapper.in("parent_geo_id", geoIds);
countWrapper.groupBy("parent_geo_id");
countWrapper.select("parent_geo_id as parentGeoId","count(*) as count");
List<Map<String, Object>> listMaps = listMaps(countWrapper);
Map<String, Long> subNodeAmountMap = listMaps.stream().collect(Collectors.toMap(e-> (String) e.get("parentGeoId"), e-> (Long) e.get("count")));
2、常用方法总结
3、LambdaQueryWrapper 查询条件同时使用 and 和 or sql 写法:
DELETE
FROM
Permission_Menu_Rel
WHERE
permissionId = 'permissionId'
AND (
( sysId = 'sysId1' AND menuId IN ( '' menuId1, 'menuId2' ) )
OR
( sysId = 'sysId2' AND menuId IN ( '' menuId3, 'menuId3' ) )
);
mybatis plus LambdaQueryWrapper 写法:
public void removePermissionMenu(String permissionId, Map<String, List<String>> relSysMenuMap) {
if (StringUtils.isBlank(permissionId) || UtilValidate.isEmpty(relSysMenuMap)) {
return ;
}
LambdaQueryWrapper<PermissionMenuRel> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(PermissionMenuRel:: getPermissionId, permissionId);
queryWrapper.and(qw -> {
relSysMenuMap.forEach((systemId,menuIds) -> {
if (StringUtils.isNotBlank(systemId) && UtilValidate.isNotEmpty(menuIds)) {
queryWrapper.or(mqw -> mqw.eq(PermissionMenuRel:: getSystemId, systemId).in(PermissionMenuRel:: getMenud, menuIds));
}
});
});
remove(queryWrapper);