peng
2025-11-06 c4938f6f4e839890b032c75c7a57333a6a9157a9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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<News, Long> {
 
    Page<News> findByStateAndTitleContainingOrderByCreateTimeDesc(Integer state, String title, Pageable pageable);
 
    Page<News> findByTitleContainingOrderByCreateTimeDesc(String title, Pageable pageable);
 
    Page<News> findByStateOrderByCreateTimeDesc(Integer state, Pageable pageable);
 
    List<News> findByStateOrderByCreateTimeDesc(Integer state);
 
    @Query("SELECT n FROM News n WHERE n.state = 1 ORDER BY n.createTime DESC")
    List<News> findPublishedNews();
 
    @Query("SELECT n FROM News n WHERE n.state = 1 ORDER BY n.createTime DESC")
    Page<News> findPublishedNews(Pageable pageable);
 
    @Query("SELECT n FROM News n WHERE n.id = :id AND n.state = 1")
    News findPublishedNewsById(@Param("id") Long id);
}