Files
obsidian_vault/settings/archived/学习成长/学习/计算机相关/JPA的example查询.md
T
2025-12-27 11:44:50 +08:00

22 lines
850 B
Markdown

#jpa
### 查询条件
使用Persist Object存查询条件
```java
QuestInfoPO po = new QuestInfoPO();
po.setCreatorId(StringUtils.isBlank(creatorId) ? null : creatorId);
po.setCreatedBy(StringUtils.isBlank(creatorName) ? null : creatorName);
po.setName(StringUtils.isBlank(questName) ? null : questName);
po.setStatus(status);
```
### 过滤规则
使用ExampleMatch指定过滤规则,matcher的properties使用的是表字段名
```java
ExampleMatcher matcher = ExampleMatcher.matching()
.withMatcher("creator_id", match -> match.exact())
.withMatcher("created_by", match -> match.contains())
.withMatcher("name", match -> match.contains())
.withMatcher("status", match -> match.exact())
.withIgnoreNullValues();
```
### 排除空条件
使用withIgnoreNullValues()排除po中的null条件