<MetaItem> wrapper = new QueryWrapper<MetaItem>()
.select("set_id,count(0) as field_count")
.in("set_id",setids)
.groupBy("set_id");

List<Map<String,Object>> list = itemService.listMaps(wrapper);

注意要用 listMaps ,返回的是 Map<String,Object>

示例:

public Result<?> queryPageList(MetaSet metaSet,
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
HttpServletRequest req) {
QueryWrapper<MetaSet> queryWrapper = QueryGenerator.initQueryWrapper(metaSet, req.getParameterMap());
Page<MetaSet> page = new Page<MetaSet>(pageNo, pageSize);
IPage<MetaSet> pageList = metaSetService.page(page, queryWrapper);

List<MetaSet> records = pageList.getRecords();
List<String> setids = records.stream().map(f -> f.getId()).collect(Collectors.toList());

QueryWrapper<MetaItem> wrapper = new QueryWrapper<MetaItem>()
.select("set_id,count(0) as field_count")
.in("set_id",setids)
.groupBy("set_id");

List<Map<String,Object>> list = itemService.listMaps(wrapper);

records.forEach(f->{
Map<String, Object> set_id = list.stream().filter(l -> l.get("set_id").toString().equals(f.getId())).findFirst().orElse(null);
if(set_id!=null){
f.setFieldCount(Integer.valueOf(set_id.get("field_count").toString()));
}
});
pageList.setRecords(records);

return Result.OK(pageList);
}