diff --git a/src/main/java/com/dl/officialsite/sharing/SharingController.java b/src/main/java/com/dl/officialsite/sharing/SharingController.java index 1548fe9f..46a363b3 100644 --- a/src/main/java/com/dl/officialsite/sharing/SharingController.java +++ b/src/main/java/com/dl/officialsite/sharing/SharingController.java @@ -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){ diff --git a/src/main/java/com/dl/officialsite/sharing/SharingService.java b/src/main/java/com/dl/officialsite/sharing/SharingService.java index 1cfa3945..4e149b2a 100644 --- a/src/main/java/com/dl/officialsite/sharing/SharingService.java +++ b/src/main/java/com/dl/officialsite/sharing/SharingService.java @@ -37,6 +37,7 @@ import java.util.List; import java.util.Objects; import java.util.Optional; +import org.springframework.util.StringUtils; @Service @Slf4j @@ -216,7 +217,7 @@ public Page searchSharing(ShareSearchVo searchVo, Pageable pageable) { Page page = sharingRepository.findAll( (Specification) (root, query, criteriaBuilder) -> { List predicates = new LinkedList<>(); - if (searchVo.getTheme() != null) { + if (StringUtils.hasText(searchVo.getTheme())) { predicates.add( criteriaBuilder.like(root.get("theme"), "%" + searchVo.getTheme() + "%")); } @@ -237,7 +238,7 @@ public Page 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; }