电商系统 常用代码 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);
posted @ 2020-12-29 14:56  古兴越  阅读(608)  评论(0编辑  收藏  举报