整理的java jdk1.8跟mybatiseplus

1.Lambor表达式
List<User> attachmentList = service.list(queryWrapper);
//判断是否重名 获取list中的文件名
Set attachSet = new HashSet(attachmentList.stream().map(User::getFileName).collect(Collectors.toList()));

2.mybatis plus 更新语句:
service.update(new UpdateWrapper<User>().set("title",title).eq("code",code).eq("tree_id",id));

3. mybatise plus 删除语句:
service.remove(new QueryWrapper<User>().eq("code",code).eq("tree_id",id));

4.查询list语句:

List<User> l = this.list(new QueryWrapper<User>().eq("type_code",User.getTypeCode()).eq("if_open",1));
5.取出list中的id:
Set<Long> declarationIdList = groupDeclarationList.stream().map(QCAwardPreauditGroupDeclarationDO::getDeclarationId).collect(Collectors.toSet());

6.mybatise plus 查询语句:
ProjectTodoDO lastCursorTodo = todoService.getOne(new QueryWrapper<ProjectTodoDO>()
.eq("type_code",PROCESS_CODE).eq("project_id",projectId).eq("type_number",processCursor)
.orderByDesc("sys_create_time").last("limit 1"));
7.将数组字符串转为字符串数组,然后过滤,取数量
long count = Arrays.stream(declaration.getDeclarationGroupMemberIds().split(",")).filter(e -> e.equals(user.getId().toString())).count();

8.filter findAny()
List<String> lines = Arrays.asList("spring", "node", "mkyong","mkyong");
System.out.println(lines);
//从集合中获得元素
String item = lines.stream().filter(line-> "mkyong".equals(line)).findAny().orElse(null); (filter为过滤,line为lines中的一个元素,lines.stream().filter(line-> "mkyong".equals(line)) 表示过滤出lines中名字为mkyong的line,

findAny()表示将其中任意一个返回,.orElse(null)表示如果一个都没找到返回null) //输出结果为: mkyong
List<String> list = lines.stream().filter(line-> !"mkyong".equals(line)).collect(Collectors.toList());  
输出结果为:spring node

9.Collectors.joining()
List<String> list = Arrays.asList("A","B","C","D");
String result = list.stream().collect(Collectors.joining());
System.out.println(result); //结果为 ABCD
String result1 = list.stream().collect(Collectors.joining(","));
System.out.println(result1);//结果为 A,B,C,D

String result2 = list.stream().collect(Collectors.joining(",","[","]"));//以逗号分割,前缀为[ 后缀为 ]
System.out.println(result2);//结果为 [A,B,C,D]
10.过滤type为1的,跟type为2的
List<User> chiefExpertList = expertList.stream().filter(e -> e.getType().equals(1)).collect(Collectors.toList());
List<User> otherExpertList = expertList.stream().filter(e -> e.getType().equals(2)).collect(Collectors.toList());
11.
取出专家名字并以逗号分隔:
String names = otherExpertList.stream().map(User::getExpertName).collect(Collectors.joining(","));
12.
List<User> expertList = service.list(new QueryWrapper<User>().eq("group_id", group.getId()));

//主用户
List<User> chiefExpertList = expertList.stream().filter(e -> e.getType().equals(1)).collect(Collectors.toList());
//副用户
List<User> otherExpertList = expertList.stream().filter(e -> e.getType().equals(2)).collect(Collectors.toList());
//其他用户
List<String> otherUserIdList = Arrays.asList(do.getUserIds().split(","));
List<User> otherExpertList = expertList.stream().filter(e -> otherUserIdList.contains(e.getExpertId().toString())).collect(Collectors.toList());
String userNames = otherExpertList.stream().map(User::getExpertName).collect(Collectors.joining(","));

 

  


原文地址:https://www.cnblogs.com/xiaoxiao1120/p/15608189.html