代码如下
@GetMapping("/接口名")
public ResultVo<IPage<Ceshiform>> 名称(Page<Ceshiform> page, Ceshiform ceshiform) {
val result = ceshiService.lambdaQuery()
.orderByDesc(Ceshiform::getAddtime)//分页排序用的是时间
.page(page);
List<Ceshiform> ceshiforms = result.getRecords();//获取分页result里的数据
ceshiforms.forEach(item -> {
//通过userid查询对应的用户信息//我这里查询的是对应关联表的用户信息,对应字段userid
UserMain UserMain = userMainMapper.getById(item.getUserid());
if (UserMain != null) {
String username = userMain.getUsername();
// 设置到Ceshiform对象中
item.setUsername(username);
}
});
// 在这里进行过滤
String desiredNickname = ceshiform.getUsername();
if (desiredNickname!=null){
List<Ceshiform> filteredTopups = ceshiforms.stream()
.filter(item -> item.getUsername() != null && item.getUsername().contains(desiredNickname))
.collect(Collectors.toList());//开始过滤,这里是对应用户名模糊查询,模糊的话用.contains,相等的话用.equal
result.setRecords(filteredTopups);
}else{
result.setRecords(ceshiforms);
}
return ResultVo.success(result);
}