package com.rongyichuang.news.repository; import com.rongyichuang.news.entity.News; 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.Query; import org.springframework.data.repository.query.Param; import java.util.List; public interface NewsRepository extends JpaRepository { Page findByStateAndTitleContainingOrderByCreateTimeDesc(Integer state, String title, Pageable pageable); Page findByTitleContainingOrderByCreateTimeDesc(String title, Pageable pageable); Page findByStateOrderByCreateTimeDesc(Integer state, Pageable pageable); List findByStateOrderByCreateTimeDesc(Integer state); @Query("SELECT n FROM News n WHERE n.state = 1 ORDER BY n.createTime DESC") List findPublishedNews(); @Query("SELECT n FROM News n WHERE n.state = 1 ORDER BY n.createTime DESC") Page findPublishedNews(Pageable pageable); @Query("SELECT n FROM News n WHERE n.id = :id AND n.state = 1") News findPublishedNewsById(@Param("id") Long id); }