refactor(service): 重构服务接口和实现类结构
将服务接口从service包移动到service.imp包 修复ArticleRepository中viewCount的COALESCE处理 添加getPublishedArticles方法获取已发布文章 优化incrementViewCount方法使用仓库直接更新 修正HelpController中README_API.md路径
This commit is contained in:
@@ -68,7 +68,7 @@ public interface ArticleRepository extends JpaRepository<Article, Integer> {
|
||||
* @param articleid 文章的唯一标识符,通过@Param注解将方法参数与查询参数绑定
|
||||
*/
|
||||
@Modifying
|
||||
@Query("UPDATE Article a SET a.viewCount = a.viewCount + 1 WHERE a.articleid = :articleid")
|
||||
@Query("UPDATE Article a SET a.viewCount = COALESCE(a.viewCount, 0) + 1 WHERE a.articleid = :articleid")
|
||||
void incrementViewCount(@Param("articleid") Integer articleid);
|
||||
|
||||
/**
|
||||
@@ -79,4 +79,11 @@ public interface ArticleRepository extends JpaRepository<Article, Integer> {
|
||||
*/
|
||||
@Query("SELECT a FROM Article a WHERE a.status = 1 ORDER BY a.viewCount DESC")
|
||||
List<Article> findMostViewed();
|
||||
/**
|
||||
* 根据状态查询文章列表
|
||||
* @param status 文章状态,0-草稿,1-已发布,2-已删除
|
||||
* @return 返回符合状态条件的文章列表
|
||||
*/
|
||||
@Query("SELECT a FROM Article a WHERE a.status = :status")
|
||||
List<Article> findByStatus(@Param("status") Integer status);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user