List<User> list = userService.list(wrapper);
// int类型
int age = list.stream().mapToInt(User::getAge).sum();
// long类型
long age = list.stream().mapToLong(User::getAge).sum();
// double类型
double age = list.stream().mapToDouble(User::getAge).sum();
// BigDecimal 类型
BigDecimal age = list.stream().map(User::getAge).reduce(BigDecimal.ZERO, BigDecimal::add);
原文链接:https://blog.csdn.net/m0_62217139/article/details/125170281