Contents
  1. 1. Query
    1. 1.1. QueryWrapper
    2. 1.2. Basic Query
    3. 1.3. Aggregation Query

Query

QueryWrapper

QueryWrapper

1
2
3
4
5
6
7
// usage 1
QueryWrapper<SysUser> queryWrapper = new QueryWrapper<SysUser>()
.eq("user_id", userId);

// usage 2
QueryWrapper<SysUser> queryWrapper = Wrappers.query(sysUser)
.eq("user_id", userId);

LambdaQueryWrapper

1
2
3
4
5
6
7
8
9
10
11
// usage 1
LambdaQueryWrapper<SysUser> lambdaQueryWrapper = new LambdaQueryWrapper<SysUser>()
.eq(SysUser::getUserId, userId);

// usage 2
LambdaQueryWrapper<SysUser> lambdaQueryWrapper = Wrappers.lambdaQuery(sysUser)
.eq(SysUser::getUserId, userId);

// usage 3
LambdaQueryWrapper<SysUser> lambdaQueryWrapper = Wrappers.lambdaQuery(SysUser.class)
.eq(SysUser::getUserId, userId);

Convert QueryWrapper to LambdaQueryWrapper

1
2
3
4
LambdaQueryWrapper<SysUser> lambdaQueryWrapper = new QueryWrapper<SysUser>()
.eq("user_id", userId)
.lambda()
.eq(SysUser::getType, type);

Basic Query

An example

1
2
3
4
5
6
List<SysUser> sysUserList = userService.list(
new QueryWrapper<SysUser>()
.select("name")
.eq("type", type)
.orderByDesc("id")
.last("limit 10"));

from

1
new QueryWrapper<Entity>()

select

1
wrapper.select("column 1", "column 2")

where

1
2
3
wrapper.eq("type", 1)
.in("user_id", userIds)
.ge("age", 18)

and…or

1
2
wrapper.and(wrapper -> wrapper.eq("type", 1)
.or().eq("type", 2))

order by

1
wrapper.orderByDesc("id")

limit

1
wrapper.last("limit 10")

Aggregation Query

An example

1
2
3
List<Map<String, Object>> mapList = userService.listMaps(new QueryWrapper<SysUser>()
.select("count(*) as typeCount")
.groupBy("type"));

group by

1
wrapper.groupBy("type"));

having

1
wrapper.having("COUNT(*) > 10"))
Contents
  1. 1. Query
    1. 1.1. QueryWrapper
    2. 1.2. Basic Query
    3. 1.3. Aggregation Query