Skip to content

Commit

Permalink
Merge pull request #255 from cheng521521/main
Browse files Browse the repository at this point in the history
fix: share function not condition search
  • Loading branch information
yanyanho authored May 30, 2024
2 parents 8c4f8a4 + 71305b7 commit 06d7ea0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public BaseResponse loadSharing(@RequestParam(value = "pageNo",defaultValue = "1
/**
* 条件搜索
*/
@PostMapping("search")
@PostMapping("/search")
public BaseResponse searchSharing(@RequestBody ShareSearchVo searchVo, @RequestParam(value =
"pageNo",defaultValue = "1") int pageNumber,
@RequestParam(value = "pageSize",defaultValue = "20") int pageSize){
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/dl/officialsite/sharing/SharingService.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import org.springframework.util.StringUtils;

@Service
@Slf4j
Expand Down Expand Up @@ -216,7 +217,7 @@ public Page<Share> searchSharing(ShareSearchVo searchVo, Pageable pageable) {
Page<Share> page = sharingRepository.findAll(
(Specification<Share>) (root, query, criteriaBuilder) -> {
List<Predicate> predicates = new LinkedList<>();
if (searchVo.getTheme() != null) {
if (StringUtils.hasText(searchVo.getTheme())) {
predicates.add(
criteriaBuilder.like(root.get("theme"), "%" + searchVo.getTheme() + "%"));
}
Expand All @@ -237,7 +238,7 @@ public Page<Share> searchSharing(ShareSearchVo searchVo, Pageable pageable) {
predicates.add(criteriaBuilder.greaterThan(root.get("date"), searchVo.getDate()));
}
query.orderBy(criteriaBuilder.desc(root.get("createTime")));
return null;
return criteriaBuilder.and(predicates.toArray(new Predicate[0]));
}, pageable);
return page;
}
Expand Down

0 comments on commit 06d7ea0

Please sign in to comment.