mybatis-plus分组求和
平常lambdaQuery写习惯了突然发现lambdaQuery好像不能求和,捡一下QueryWrapper写法1
2
3
4QueryWrapper<Entity> yearQueryWrapper = new QueryWrapper<>();
yearQueryWrapper.select("bid_year as name,sum(amount) as value");
yearQueryWrapper.groupBy("bid_year").orderByAsc("bid_year");
List<Map<String, Object>> yearMapList= bidInforService.listMaps(yearQueryWrapper);
groupby多个字段1
2
3
4
5
6
7// 源码信息
default Children groupBy(R... columns) {
return this.groupBy(true, columns);
}
QueryWrapper.groupBy("bid_year","bid_month");
map与javaBean对象转换
方法一:用Apache BeanUtils将Map转Bean
1 | // 用apache的BeanUtils实现Map covert to Bean |
方法二:自封装工具类
1 | public class MapToObjectUtil { |
实战使用:1
List<Entity> yearList = yearMapList.stream().map(item -> MapToObjectUtil.map2Object(item, Entity.class)).collect(Collectors.toList());
...
...
00:00
00:00
This is copyright.