整理的java jdk1.8跟mybatiseplus


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

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

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

4.查询list语句:

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

6.mybatise plus 查询语句:
ProjectTodoDO lastCursorTodo = todoService.getOne(new QueryWrapper()
.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 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 list = lines.stream().filter(line-> !"mkyong".equals(line)).collect(Collectors.toList());  
输出结果为:spring node

9.Collectors.joining()
List 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 chiefExpertList = expertList.stream().filter(e -> e.getType().equals(1)).collect(Collectors.toList());
List 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 expertList = service.list(new QueryWrapper().eq("group_id", group.getId()));

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

 

						  
					  

相关