//使用java8 api方法list.stream().map().collect(Collectors.toList()) //userList User实体类对象集合 //User 实体类 //getId 实体类属性的get方法 List ids= userList.stream().map(User::getId).collect(Collectors.toList()) //或者 把数据放到map根据user.getId(条件) 循环 在转换成list List ids= userList.stream().map(user->user.getId()).collect(Collectors.toList());
//过滤list集合中属性type为1的值并赋值给permissions集合 在返回list集合 .collect(Collectors.toList()) 转换成list集合 List permissions = list.stream().filter(l -> l.getType().equals(1)) .collect(Collectors.toList());
原文链接:https://blog.csdn.net/weixin_43204347/article/details/107004994
流分类
@Override
public List<OrderDetail> getScenicOrders(Member userInfo) {
List<Order> paidList = orderService.getPaidList(userInfo.getId());
List<String> orderIds = paidList.stream().map(f -> {
return f.getId();
}).collect(Collectors.toList());
return orderDetailDao.findByMemberIdAndTypeAndOrderIdIn(userInfo.getId(), 1, orderIds);
}
@Override
public List<OrderDetail> getHotelOrders(Member userInfo) {
List<Order> paidList = orderService.getPaidList(userInfo.getId());
List<String> orderIds = paidList.stream().map(f -> {
return f.getId();
}).collect(Collectors.toList());
return orderDetailDao.findByMemberIdAndTypeAndOrderIdIn(userInfo.getId(), 2, orderIds);
}
@Override
public List<OrderDetail> getSpecialtyOrders(Member userInfo) {
List<Order> paidList = orderService.getPaidList(userInfo.getId());
List<String> orderIds = paidList.stream().map(f -> {
return f.getId();
}).collect(Collectors.toList());
return orderDetailDao.findByMemberIdAndTypeAndOrderIdIn(userInfo.getId(), 3, orderIds);
}
@Override
public List<OrderDetail> getProductOrders(Member userInfo) {
List<Order> paidList = orderService.getPaidList(userInfo.getId());
List<String> orderIds = paidList.stream().map(f -> {
return f.getId();
}).collect(Collectors.toList());
return orderDetailDao.findByMemberIdAndTypeAndOrderIdIn(userInfo.getId(), 4, orderIds);
}
|