Lambda

Lambda

Lambda链式查询

List<UserEntity> users = new LambdaQueryChainWrapper<UserEntity>(userMapper)
            .like(User::getName, "雨").ge(User::getAge, 20).list();

删除

public Boolean removeTopic(TopicTopicRequestVo topicTopicRequestVo) {
	return this.remove(Wrappers.<TopicTopic>lambdaQuery().eq(TopicTopic::getAuthor, topicTopicRequestVo.getAuthor()));
	}

修改

public Boolean updateByCondition(TopicTopicRequestVo topicTopicRequestVo) {
		TopicTopic topicTopic = new TopicTopic();
		BeanUtils.copyProperties(topicTopicRequestVo, topicTopic);
		return this.update(topicTopic, Wrappers.<TopicTopic>lambdaQuery().eq(TopicTopic::getAuthor, topicTopicRequestVo.getAuthor()));
	}

oldList转newList

public static List<AccountVo> oldListToNewList(List<Account> list){
    return list.stream().map(e -> {
        AccountVo vo = new AccountVo();
        BeanUtils.copyProperties(e,vo);
        return vo;
    }).collect(Collectors.toList());
    
}

list 转 HashMap 一个key

public static Map<Long, Account> getIdAccountMap2(List<Account> list) {
    return list.stream().collect(Collectors.toMap(Account::getId, Function.identity(), (val1, val2) -> val2));

}

list 转 HashMap 多个key,如果key重复取第1个

public static Map<String, Account> getIdAccountMap2(List<Account> list) {
    return list.stream().collect(Collectors.toMap(k->k.getId()+k.getName(), Function.identity(), (val1, val2) -> val1));

}

list 转 HashMap 多个key,如果key重复取第2个

public static Map<String, Account> getIdAccountMap2(List<Account> list) {
    return list.stream().collect(Collectors.toMap(k->k.getId()+k.getName(), Function.identity(), (val1, val2) -> val2));

}

list转LinkedHashMap

public static Map<Integer, List<Student>> listToMap1(List<Student> list) {
		return list.stream().collect(Collectors.toMap(k->k.getId(), v ->
				Lists.newArrayList(v),(List<Student> newValueList, List<Student> oldValueList)->
		{newValueList.addAll(oldValueList);
			return newValueList;
		},LinkedHashMap::new));
	}
//map转为list
	private static List<Student> mapToList(Map<Integer,List<Student>> map) {
		List<Student> lists = new ArrayList<>();
		
		map.forEach((k,v)->{
			List<Student> collect = v.stream().map(o -> {
				Student student = new Student();
				student.setId(Integer.valueOf(k));
				student.setNames(objectToNameList(v));
				student.setJobs(objectToJobList(v));
				return student;
			}).collect(Collectors.toList());
			lists.addAll(collect);
		});
		return lists.stream().distinct().collect(Collectors.toList());
		
	}
	
	//list转map
	public static Map<Integer, List<Student>> listToMap(List<Student> list) {
		return list.stream().collect(Collectors.groupingBy(Student::getId));
	}
	
	//把对象某个属性转为集合
	public static List<String> objectToNameList(List<Student> list){
		return list.stream().map(Student::getName).collect(Collectors.toList());
	}
	
	public static List<String> objectToJobList(List<Student> list){
		return list.stream().map(Student::getJob).collect(Collectors.toList());
	}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值