電商系統 常用代碼 Java


查詢一個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);


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM