feat: 实现API文档支持与系统优化

refactor(ArticleRepository): 修正@Param注解导入错误并优化查询方法
fix(ArticleService): 解决事务回滚问题并优化日志配置
feat(SecurityConfig): 添加Spring Security配置禁用默认认证
docs: 添加详细API文档README_API.md
feat(HelpController): 实现Markdown文档渲染API
style: 清理无用注释和导入
build: 更新pom.xml依赖和插件配置
chore: 优化application.properties配置
This commit is contained in:
qingfeng1121
2025-10-10 16:20:13 +08:00
parent fdb0608751
commit 60f4752124
14 changed files with 7792 additions and 39 deletions

View File

@@ -1,30 +1,66 @@
package com.qf.myafterprojecy.repository;
import com.qf.myafterprojecy.pojo.Article;
import org.apache.ibatis.annotations.Param;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Optional;
@Repository
@Repository // 表明这是一个数据访问层组件,用于持久层操作
//public interface ArticleRepository extends CrudRepository<Article,Integer> {
//}
public interface ArticleRepository extends JpaRepository<Article, Integer> {
/**
* 根据文章ID查询文章信息的方法
* 使用JPQLJava Persistence Query Language进行查询
*
* @param id 文章的唯一标识符,作为查询条件
* @return 返回一个Optional<Article>对象可能包含文章信息也可能为空如果未找到对应ID的文章
*/
@Query("SELECT a FROM Article a WHERE a.articleid = :id")
Optional<Article> findById(@Param("id") Integer id);
/**
* 根据文章ID查询已发布的文章
* 使用JPQL查询语句只查询状态为1已发布且指定ID的文章
*
* @param id 作者ID作为查询参数传入
* @return 返回符合查询条件的文章列表
*/
@Query("SELECT a FROM Article a WHERE a.status = 1")
List<Article> findPublishedByAuthor();
@Query("SELECT a FROM Article a WHERE a.status = 1 AND a.articleid = :articleid")
List<Article> findPublishedByAuthor(@Param("authorId") Integer authorId);
@Query("SELECT a FROM Article a WHERE a.status = 1 AND a.typeid = :typeid")
/**
* 根据分类ID查询已发布的文章列表
* 使用JPQL查询语句筛选状态为已发布(status=1)且指定分类(typeid)的文章
*
* @param typeid 分类ID通过@Param注解映射到查询语句中的:typeid参数
* @return 返回符合条件Article对象的列表
*/
@Query("SELECT a FROM Article a WHERE a.status = 1 AND a.typeid = :categoryId")
List<Article> findPublishedByCategory(@Param("categoryId") Integer categoryId);
/**
* 使用@Modifying注解标记这是一个修改操作通常用于UPDATE或DELETE语句
* 使用@Query注解定义自定义的JPQL查询语句
* 该查询用于将指定文章的浏览量(viewCount)增加1
*
* @param articleid 文章的唯一标识符,通过@Param注解将方法参数与查询参数绑定
*/
@Modifying
@Query("UPDATE Article a SET a.viewCount = a.viewCount + 1 WHERE a.id = :id")
void incrementViewCount(@Param("id") Integer id);
@Query("UPDATE Article a SET a.viewCount = a.viewCount + 1 WHERE a.articleid = :articleid")
void incrementViewCount(@Param("articleid") Integer articleid);
/**
* 根据浏览量降序查询状态为1的所有文章
* 该查询使用JPQL语句从Article实体中选取数据
*
* @return 返回一个Article对象的列表按浏览量(viewCount)降序排列
*/
@Query("SELECT a FROM Article a WHERE a.status = 1 ORDER BY a.viewCount DESC")
List<Article> findMostViewed();
}

View File

@@ -4,5 +4,5 @@ import com.qf.myafterprojecy.pojo.Message;
import org.springframework.data.repository.CrudRepository;
public interface MessageRepository extends CrudRepository<Message, Integer> {
// 可根据需要添加自定义查询方法
}