查詢一個map出來
@Override
public Map<String, List<GoodsTitle>> mapByStoreIds(List<Long> storeIds) {
List<GoodsTitle> list = new LambdaQueryChainWrapper<>(baseMapper)
.in(GoodsTitle::getStoreId, storeIds)
.list();
Map<String, List<GoodsTitle>> map = list.stream().collect(Collectors.groupingBy(GoodsTitle::getTitle));
return map;
}
list根據某個字段分組,轉換為map
https://www.cnblogs.com/wong-/p/14060212.html
//list<對象> 轉換Map 並根據某個字段分組
Map<String, List<User>> collect = users.stream().collect(Collectors.groupingBy(User::getUserName));
對象屬性復制 hutool
BeanUtil.copyProperties(detailDTO, detail);
添加單元測試
在class上直接右鍵 -> Go To -> Test -> Create New Test
字符串格式化
MessageFormat.format("explorer /e,/select,{0}", domain)
比較是否相等
比較兩個Integer類型的值是否相等,就用equals()
方法
獲取當前時間
LocalDateTime.now()
遍歷集合
for( String name : names ) {
System.out.print( name );
System.out.print(",");
}
查詢某個字段 映射到list
List<Long> ids = pictureTypes
.stream()
.map(c -> c.getId())
.collect(Collectors.toList());
List排序
List<Store> list = storeService.list()
.stream()
.sorted(Comparator.comparing(Store::getSort))
.collect(Collectors.toList());
List排序 倒序
list = list.stream().sorted(Comparator.comparing(Material::getUpdateTime).reversed()).collect(Collectors.toList());
從list中查找一個元素
Order order = orders.stream()
.filter(item -> Func.equals(item.getPlatformOrderSn(), platformOrderSn))
.findFirst()
.orElse(null);