feat(singer): 优化歌手搜索功能
- 修改了前端 Singer.vue 文件,增加了对 keyword 的判断,以显示不同的标题 - 更新了后端 SingerServiceImpl 文件,改进了搜索逻辑,支持多字段查询
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
// 类型查询
|
||||
|
||||
@@ -243,7 +243,7 @@ onMounted(() => {
|
||||
</div>
|
||||
|
||||
<!-- 热门歌手 -->
|
||||
<div class="hot-singers" v-if="activeType === null && currentPage === 1">
|
||||
<div class="hot-singers" v-if="!keyword && activeType === null && currentPage === 1">
|
||||
<h2>热门歌手</h2>
|
||||
<div class="singer-list" v-loading="loadingHot">
|
||||
<div
|
||||
@@ -277,7 +277,8 @@ onMounted(() => {
|
||||
|
||||
<!-- 歌手列表 -->
|
||||
<div class="all-singers">
|
||||
<h2 v-if="activeType === null && currentPage === 1">全部歌手</h2>
|
||||
<h2 v-if="keyword">搜索结果</h2>
|
||||
<h2 v-else-if="activeType === null && currentPage === 1">全部歌手</h2>
|
||||
<div class="singer-list" v-loading="loading">
|
||||
<div
|
||||
v-for="singer in singers"
|
||||
|
||||
Reference in New Issue
Block a user