ArticleRepository.java 1.9 KB
Newer Older
U
u014427391 已提交
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 31 32 33 34 35 36 37 38 39 40 41
package net.myblog.repository;

import java.util.Date;
import java.util.List;

import net.myblog.entity.Article;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;

public interface ArticleRepository extends PagingAndSortingRepository<Article,Integer>{
	/**
	 * 获取博主推荐的文章
	 * @return
	 */
	@Query("from Article a where a.articleSupport=1 order by a.articleId asc")
	public List<Article> findSupportArticle();
	
	/*SELECT YEAR(articleTime) AS 'year',MONTH(articleTime) AS 'month',COUNT(*) AS 'count' FROM article 
	GROUP BY YEAR(articleTime) DESC,MONTH(articleTime);*/
	/**
	 * 文章归档信息获取
	 * @return
	 */
	@Query(value="select year(a.articleTime) as year,month(a.articleTime) as month,"
			+ "count(a) as count from Article a group by year(a.articleTime),month(a.articleTime)",
			countQuery="select count(1) from (select count(1) from Article a group by year(a.articleTime),month(a.articleTime))")
	public List<Object[]> findArticleGroupByTime();
	
	/**
	 * 按月份获取文章信息
	 * @param yearmonth
	 * @return
	 */
	@Query("from Article a where date_format(a.articleTime,'%Y%m')=date_format((:yearmonth),'%Y%m') "
			+ "order by articleTime desc")
	public List<Article> findArticleByMonth(@Param("yearmonth")Date yearmonth);
S
smileNicky 已提交
42 43 44 45 46 47 48 49

	/**
	 * 获取文章详情信息
	 * @param articleId
	 * @return
	 */
	@Query("from Article a where a.articleId=:articleId")
	public Article getArticleInfo(@Param("articleId")int articleId);
S
smileNicky 已提交
50 51 52 53 54 55 56 57

	/**
	 * 根据类别id获取文章列表
	 * @param typeId
	 * @return
	 */
	@Query("from Article a where a.typeId=:typeId")
	public List<Article> listArticleByTypeId(@Param("typeId")int typeId);
U
u014427391 已提交
58
}