用法
public void select() {
LazyUserTest lazyUserTest = new LazyUserTest();
lazyUserTest.setUsername("紧");
lazyUserTest.setSex(LazyUserTest.Sex.MAN);
lazyUserTest.setId(12L);
lazyLambdaStream.upsert(lazyUserTest);
lazyLambdaStream.update(lazyUserTest, LazyWrappers.<LazyUserTest>lambdaWrapper().eq(LazyUserTest::getSex, LazyUserTest.Sex.MAN));
List<LazyUserTest> lazyUserTests = lazyLambdaStream.selectList(LazyWrappers.<LazyUserTest>lambdaWrapper()
.inOr(LazyUserTest::getAge, List.of(18, 19, 20))
);
System.out.println("18、19、20 age user:" + lazyUserTests);
// 打印信息
// 执行类型: =====> SELECT
//执行sql: =====> SELECT lazy_user_test.birthday as birthday , lazy_user_test.sex as sex , lazy_user_test.id as id , lazy_user_test.username as username , lazy_user_test.is_deleted as is_deleted , lazy_user_test.age as age from lazy_user_test where ( lazy_user_test.age = 18 or lazy_user_test.age = 19 or lazy_user_test.age = 20 ) and is_deleted = false
// 18、19、20 age user:[]
}
public void select() {
LazyUserTest lazyUserTest = new LazyUserTest();
lazyUserTest.setUsername("紧");
lazyUserTest.setSex(LazyUserTest.Sex.MAN);
lazyUserTest.setId(12L);
lazyLambdaStream.upsert(lazyUserTest);
lazyLambdaStream.update(lazyUserTest, LazyWrappers.<LazyUserTest>lambdaWrapper().eq(LazyUserTest::getSex, LazyUserTest.Sex.MAN));
LazyUserTest lazyUserTest = lazyLambdaStream.selectOne(LazyWrappers.<LazyUserTest>lambdaWrapper()
.eq(LazyUserTest::getId, 12L)
.eq(LazyUserTest::getIsDeleted, false)
);
System.out.println(" user :" + lazyUserTest);
// 打印信息
// 执行类型: =====> SELECT
//执行sql: =====> SELECT lazy_user_test.birthday as birthday , lazy_user_test.sex as sex , lazy_user_test.id as id , lazy_user_test.username as username , lazy_user_test.is_deleted as is_deleted , lazy_user_test.age as age from lazy_user_test where lazy_user_test.id = 12 and is_deleted = false
// 18、19、20 age user:[]
}
@Test
public void count(){
Long count = lazyLambdaStream.count(LazyWrappers.<LazyUserTest>lambdaWrapper()
.eq(LazyUserTest::getIsDeleted, false)
.eq(LazyUserTest::getSex, LazyUserTest.Sex.MAN)
.gt(LazyUserTest::getAge, 10)
.gt(LazyUserTest::getBirthday, LocalDateTime.now()));
// 如同执行如下sql select count(1) from lazy_user_test where lazy_user_test.is_deleted = false and lazy_user_test.sex = 'MAN' and lazy_user_test.age > 10 and lazy_user_test.birthday > '2024-02-06 20:21:03' and lazy_user_test.is_deleted = false
System.out.println("lazyLambdaStream.count:"+count);
}
@Test
public void exists(){
boolean exists = lazyLambdaStream.exists(LazyWrappers.<LazyUserTest>lambdaWrapper()
.eq(LazyUserTest::getIsDeleted, false)
.eq(LazyUserTest::getSex, LazyUserTest.Sex.MAN)
.gt(LazyUserTest::getAge, 10)
.gt(LazyUserTest::getBirthday, LocalDateTime.now()));
// 如同执行如下sql select count(1) from lazy_user_test where lazy_user_test.is_deleted = false and lazy_user_test.sex = 'MAN' and lazy_user_test.age > 10 and lazy_user_test.birthday > '2024-02-06 20:21:03' and lazy_user_test.is_deleted = false
System.out.println("lazyLambdaStream.exists:"+exists);
}
@Test
public void selectName(){
String userName = lazyLambdaStream.selectOne(LazyWrappers.<LazyUserTest>lambdaWrapper()
.eq(LazyUserTest::getId, 1)
.eq(LazyUserTest::getIsDeleted, false)
.onlyUseAs()
.as(LazyUserTest::getUsername,LazyUserTest::getUsername),
String.class);
// SELECT lazy_user_test.username as username from lazy_user_test where lazy_user_test.id = 1 and lazy_user_test.is_deleted = false and lazy_user_test.is_deleted = false
System.out.println("只查询用户ID为1 的用户名称:"+userName);
}
@Test
public void selectNameIdAge(){
LazyUserTest userNameIdAge = lazyLambdaStream.selectOne(LazyWrappers.<LazyUserTest>lambdaWrapper()
.eq(LazyUserTest::getId, 1)
.eq(LazyUserTest::getIsDeleted, false)
.onlyUseAs()
.as(LazyUserTest::getId,LazyUserTest::getId)
.as(LazyUserTest::getAge,LazyUserTest::getAge)
.as(LazyUserTest::getUsername,LazyUserTest::getUsername)
,
LazyUserTest.class);
// SELECT lazy_user_test.id as id , lazy_user_test.username as username , lazy_user_test.age as age from lazy_user_test where lazy_user_test.id = 1 and lazy_user_test.is_deleted = false and lazy_user_test.is_deleted = false
System.out.println("只查询用户ID为1 的用户名称、ID、age:"+userNameIdAge);
}
List<Menu> menuList = lazyLambdaStream.selectList(LazyWrappers.<RoleMenuDO>lambdaWrapper()
.eq(RoleMenuDO::getIsDeleted, false)
.eq(RoleMenuDO::getRoleId, role.getId())
.internalJoin(LazyWrappers.<RoleMenuDO, MenuDO>lambdaWrapperJoin()
.eqo(RoleMenuDO::getIsDeleted, false)
.eqo(RoleMenuDO::getRoleId, role.getId())
.eq(RoleMenuDO::getMenuId, MenuDO::getId)
.eqRighto(MenuDO::getIsDeleted, false)
)
.onlyUseAs()
.as(Menu.class),
Menu.class
);