feat(singer): 优化歌手搜索功能

- 修改了前端 Singer.vue 文件,增加了对 keyword 的判断,以显示不同的标题
- 更新了后端 SingerServiceImpl 文件,改进了搜索逻辑,支持多字段查询
This commit is contained in:
ikmkj
2025-07-29 19:56:08 +08:00
parent 8aa076ded1
commit f67c6f2262
2 changed files with 8 additions and 3 deletions

View File

@@ -93,10 +93,14 @@ public class SingerServiceImpl implements SingerService {
// 构建查询条件
Specification<Singer> spec = (root, query, cb) -> {
List<Predicate> predicates = new ArrayList<>();
query.distinct(true); // 添加 distinct 查询
// 关键字查询
if (StringUtils.hasText(keyword)) {
predicates.add(cb.like(root.get("name"), "%" + keyword + "%"));
Predicate p1 = cb.like(root.get("name"), "%" + keyword + "%");
Predicate p2 = cb.like(root.get("introduction"), "%" + keyword + "%");
Predicate p3 = cb.like(root.join("musics", jakarta.persistence.criteria.JoinType.LEFT).get("name"), "%" + keyword + "%");
predicates.add(cb.or(p1, p2, p3));
}
// 类型查询