|
|
@@ -4,8 +4,10 @@ import nju.seec.helper.entity.Comment;
|
|
|
import nju.seec.helper.entity.User;
|
|
|
import nju.seec.helper.enums.ExceptionType;
|
|
|
import nju.seec.helper.exception.HelperException;
|
|
|
+import nju.seec.helper.util.StringUtils;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
+import org.springframework.data.jpa.domain.Specification;
|
|
|
import org.springframework.data.jpa.repository.JpaRepository;
|
|
|
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
|
|
import org.springframework.stereotype.Repository;
|
|
|
@@ -70,4 +72,23 @@ public interface CommentDAO extends JpaRepository<Comment, Long>, JpaSpecificati
|
|
|
* @return
|
|
|
*/
|
|
|
Page<Comment> findBySlideIdAndPageNumberAndUserAndShow(Long slideId, Integer pageNumber, User user, Boolean show, Pageable pageable);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据用户ID、关键字检索
|
|
|
+ *
|
|
|
+ * @param userId
|
|
|
+ * @param key
|
|
|
+ * @param pageable
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ default Page<Comment> findByUserIdAndKey(Long userId, String key, Pageable pageable) {
|
|
|
+ String keyPattern = StringUtils.keyPattern(key);
|
|
|
+
|
|
|
+ return this.findAll(
|
|
|
+ (Specification<Comment>) (root, query, cb) -> cb.and(
|
|
|
+ cb.equal(root.get("user").get("id"), userId),
|
|
|
+ cb.or(cb.like(root.get("title"), keyPattern), cb.like(root.get("content"), keyPattern))
|
|
|
+ )
|
|
|
+ , pageable);
|
|
|
+ }
|
|
|
}
|