目录
1、对list实体对象分页查询
AcAppRole 实体对象
@Data
public class AcAppRole {
/** 角色编码 */
private Long roleId;
/** 角色编码 */
private String roleCode;
/** 角色名称 */
private String roleName;
/** 角色所属的应用系统id */
private Long appSystemId;
}
public class AcAppRoleTest {
@Test
public void test1() {
List<AcAppRole> roleList = new ArrayList<>(100);
// 按照 系统appSystemId 分组
Map<Long, List<AcAppRole>> groupBy = null;
groupBy = roleList.stream().collect(Collectors.groupingBy(AcAppRole::getAppSystemId));
}
}
2、对list进行过滤
UserEntity 实体对象
@Data
public class UserEntity {
private static final long serialVersionUID = 1L;
/** 主键id */
private Integer id;
/** 姓名 */
private String name;
/** 性别 */
private String sex;
/** 年龄 */
private String age;
}
//获取 list中id大于20的数据
public class UserEntityTest {
@Test
public void test1() {
List<UserEntity> entityList = new ArrayList<>(100);
List<UserEntity> collect2 =
entityList.stream()
.filter(userEntity1 -> userEntity1.getId() > 20)
.collect(Collectors.toList());
}
}
3、从一个list对象转list对象的属性
AcAppRole实体对象
@ApiModelProperty(value = "主键ID")
@TableId(value = "id", type = IdType.AUTO)
private Long id;
/** 角色描述 */
@ApiModelProperty(value = "角色描述")
private String remark;
/** 角色名称 */
@ApiModelProperty(value = "角色名称")
private String name;
/** 角色所属的应用系统编码 */
@ApiModelProperty(value = "角色所属的应用系统编码")
private String appSystemCode;
public class AcAppRole3Test {
@Test
public void test1() {
List<AcAppRole> roleList = new ArrayList<>();
List<String> collect = roleList.stream().map(AcAppRole::getName).collect(Collectors.toList());
}
}