一、LambdaQueryWrapper中使用::
String departId = req.getParameter("departId");
LambdaQueryWrapper<SysUserDepart> query = new LambdaQueryWrapper<>();
query.eq(SysUserDepart::getDepId,departId);
//作用 设置SysUserDepart的getDepId字段的值为'departId'
//也可写为
QueryWrapper<SysUserDepart> wrapper = new QueryWrapper<>();
wrapper.lambda().eq(SysUserDepart::getDepId,departId);
//其作用等于QueryWrapper中的:
QueryWrapper<SysUserDepart> wrapper = new QueryWrapper<>();
wrapper.eq("dep_id", departId);
//由此避免在java代码中出现数据库字段'dep_id'字样
二、stream中使用::
List<User> list = new ArrayList<User>() {
{
add(new User("1"));
add(new User("2"));
add(new User("3"));
add(new User("4"));
}
};
List<String> userIdList= list.stream().map(User::getId).collect(Collectors.toList());
//把getId()方法当做参数传到stream内部,使stream的每个元素都传入到该方法里面执行一下
//其效果相当于
List<String> userIdList= list.stream().map(
i -> {
return i.getId();
}
).collect(Collectors.toList());
//再如:
list.forEach(System.out::println);