Jin's Dev Story

[스프링 부트 쇼핑몰 프로젝트 with JPA] 17-4. 게시판 - Repository 본문

Web & Android/스프링 부트 쇼핑몰 프로젝트 with JPA

[스프링 부트 쇼핑몰 프로젝트 with JPA] 17-4. 게시판 - Repository

woojin._. 2023. 10. 16. 20:24
이 내용은 스프링 부트 쇼핑몰 프로젝트 with JPA 책을 학습한 내용입니다.

Repository

  • BoardRepository

      import com.example.walkingmate_back.board.entity.Board;
      import org.springframework.data.domain.Pageable;
      import org.springframework.data.jpa.repository.JpaRepository;
      import org.springframework.data.jpa.repository.Query;
      import java.util.List;
    
      public interface BoardRepository extends JpaRepository<Board, Long> {
    
          // 게시글 전체 조회 - 최신 값부터
          @Query("SELECT d FROM Board d ORDER BY d.id DESC")
          List<Board> findAllBoard(Pageable pageable);
    
      }
  • BoardCommentRepository

      import com.example.walkingmate_back.board.entity.BoardComment;
      import org.springframework.data.jpa.repository.JpaRepository;
    
      public interface BoardCommentRepository extends JpaRepository<BoardComment, Long> {
    
          void deleteAllByParentId(Long id);
    
      }
  • RecommedCommentRepository

      import com.example.walkingmate_back.board.entity.RecommendComment;
      import com.example.walkingmate_back.board.entity.RecommendCommentId;
      import org.springframework.data.jpa.repository.JpaRepository;
    
      public interface RecommendCommentRepository extends JpaRepository<RecommendComment, RecommendCommentId> {
    
          boolean existsByBoardCommentIdAndUserId(Long id, String userId);
    
          void deleteByBoardCommentIdAndUserId(Long id, String userId);
      }
  • RecommendRepository

      import com.example.walkingmate_back.board.entity.Recommend;
      import com.example.walkingmate_back.board.entity.RecommendId;
      import org.springframework.data.jpa.repository.JpaRepository;
    
      public interface RecommendRepository extends JpaRepository<Recommend, RecommendId> {
    
          boolean existsByBoardIdAndUserId(Long id, String userId);
    
          void deleteByBoardIdAndUserId(Long id, String userId);
      }