1.LambdaQueryWrapper 的条件构造器方法对应Sql
代码示例:
LambdaQueryWrapper<Employee> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(Employee::getUsername,employee.getUsername());
Employee emp = employeeService.getOne(queryWrapper);
方法:
setSqlSelect | SELECT 查询字段 |
---|---|
where | WHERE 语句,拼接 + WHERE 条件 |
where | WHERE 语句,拼接 + WHERE 条件 |
and | AND 语句,拼接 + AND 字段=值 |
andNew | AND 语句,拼接 + AND (字段=值) |
or | OR 语句,拼接 + OR 字段=值 |
orNew | OR 语句,拼接 + OR (字段=值) |
eq | 等于= |
allEq | 基于 map 内容等于= |
ne | 不等于<> |
gt | 大于> |
ge | 大于等于>= |
lt | 小于< |
le | 小于等于<= |
like | 模糊查询 LIKE |
notLike | NOT LIKE模糊查询 |
in | IN 查询 |
notIn | NOT IN 查询 |
isNull | NULL 值查询 |
isNotNull | IS NOT NULL |
groupBy | 分组 GROUP BY |
having | HAVING 关键词 |
orderBy | 排序 ORDER BY |
orderAsc | Asc 排序 ORDER BY |
orderDesc | DESC 排序 ORDER BY |
exists | EXISTS 条件语句 |
notExists | NOT EXISTS 条件语句 |
between | BETWEEN 条件语句 |
notBetween | NOT BETWEEN 条件语句 |
addFilter | 自由拼接 SQL |
last | 拼接在最后,例如:last(“LIMIT 1”) |
例如:
LambdaQueryWrapper<Notice> lqw = new LambdaQueryWrapper<>();
lqw.eq(Notice::getInviteeId, notice.getInviteeId());
lqw.eq(Notice::getNoticeType, NoticeDO.NOTICE_TYPE);
lqw.orderByDesc(Notice::getCreateTime);
lqw.last("limit 1");
select * from notice where invitee_id=179 order by create_time desc limit 1;
2.注解的使用
@NotEmpty,@NotNull和@NotBlank的区别
1 @NotEmpty :不能为null,且Size>0
2 @NotNull:不能为null,但可以为empty,没有Size的约束
3 @NotBlank:只用于String,不能为null且trim()之后size>0
————————————————