首页>代码>Spring Boot+Semantic UI框架开发小而美的个人博客>/blog/src/main/java/com/lrm/dao/BlogRepository.java
package com.lrm.dao;

import com.lrm.po.Blog;
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.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by limi on 2017/10/20.
 */
public interface BlogRepository extends JpaRepository<Blog, Long>, JpaSpecificationExecutor<Blog> {

    @Query("select b from Blog b where b.recommend = true")
    List<Blog> findTop(Pageable pageable);

    @Query("select b from Blog b where b.title like ?1 or b.content like ?1")
    Page<Blog> findByQuery(String query,Pageable pageable);


    @Transactional
    @Modifying
    @Query("update Blog b set b.views = b.views+1 where b.id = ?1")
    int updateViews(Long id);

    @Query("select function('date_format',b.updateTime,'%Y') as year from Blog b group by function('date_format',b.updateTime,'%Y') order by year desc ")
    List<String> findGroupYear();

    @Query("select b from Blog b where function('date_format',b.updateTime,'%Y') = ?1")
    List<Blog> findByYear(String year);
}
最近下载更多
zolscy  LV24 2024年3月24日
zhaobing_g  LV3 2023年8月24日
锅里巴巴  LV4 2022年8月5日
wanglinddad  LV55 2022年4月6日
lehiwang  LV2 2022年3月23日
zhangyuzhu  LV10 2022年3月9日
新东方瑶酱  LV7 2022年1月29日
刘地带  LV11 2021年12月27日
931933787  LV2 2021年11月4日
739086737  LV5 2021年9月7日
最近浏览更多
短巷拥猫  LV12 5月26日
PLVAE_514  LV2 3月7日
陈小灏  LV18 2月18日
yellow_flowers  LV8 2024年7月8日
TY0165  LV20 2024年6月24日
林灵123456  LV8 2024年6月5日
f22m1a2b2  LV17 2024年5月31日
Sul_ALL  LV1 2024年5月5日
玖零定制问题修复  LV34 2024年5月4日
yrisok  LV3 2024年4月23日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友