You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

64 lines
1.8 KiB

package cc.bnblogs.mapper;
import cc.bnblogs.pojo.Article;
import cc.bnblogs.pojo.Comment;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/**
* @author zfp@bnblogs.cc
* @createTime: 2022/10/17
*/
public interface CommentMapper extends JpaRepository<Comment,Integer> {
/**
* 统计文章对应的评论数
* @param article 文章
* @return 评论个数
*/
long countByArticle(Article article);
/**
* 按照文章创建时间降序来分页
* @param article 文章
* @param pid 父评论的id
* @param pageable 分页
* @return 该页的评论
*/
Page<Comment> findAllByArticleAndPidOrderByCreatedDesc(Article article, Integer pid,Pageable pageable);
/**
* 根据父id获取所有子评论
* @param pid 评论的父id
* @return 该父评论下的所有评论
*/
List<Comment> findAllByPidOrderByCreatedDesc(Integer pid);
/**
* 将所有未读评论改为已读
*/
@Modifying
@Transactional(rollbackFor = {Exception.class})
@Query(value = "update blog_comment set view=true where view=false ", nativeQuery = true)
void readAll();
/**
* 根据view选择不同的评论
* @param view 是否已读
* @param pageable 分页器
* @return 评论列表
*/
Page<Comment> findAllByView(Boolean view, Pageable pageable);
/**
* 根据view的值统计评论数
* @param view 是否已读
* @return 评论个数
*/
Long countCommentByView(Boolean view);
}