feat(分类属性): 实现分类属性管理功能

新增分类属性相关实体、DTO、仓库、服务及控制器
扩展文章服务以支持按属性查询文章
重构文章实体将typeid改为attributeid
添加按标题查询文章功能
This commit is contained in:
qingfeng1121
2025-10-16 16:34:36 +08:00
parent 8cc4c1da1d
commit ffea3e85ae
15 changed files with 1513 additions and 2039 deletions

View File

@@ -21,6 +21,13 @@ public interface ArticleRepository extends JpaRepository<Article, Integer> {
*/
@Query("SELECT a FROM Article a WHERE a.articleid = :id")
Optional<Article> findById(@Param("id") Integer id);
/**
* 根据标题查询文章列表
* @param title 文章标题的一部分,用于模糊查询
* @return 返回符合查询条件的文章列表
*/
@Query("SELECT a FROM Article a WHERE a.title LIKE %:title%")
List<Article> findByTitle(@Param("title") String title);
/**
* 根据文章ID查询已发布的文章
* 使用JPQL查询语句只查询状态为1已发布且指定ID的文章
@@ -34,11 +41,20 @@ public interface ArticleRepository extends JpaRepository<Article, Integer> {
* 根据分类ID查询已发布的文章列表
* 使用JPQL查询语句筛选状态为已发布(status=1)且指定分类(typeid)的文章
*
* @param typeid 分类ID通过@Param注解映射到查询语句中的:typeid参数
* @param attributeid 分类ID通过@Param注解映射到查询语句中的:attributeid参数
* @return 返回符合条件Article对象的列表
*/
@Query("SELECT a FROM Article a WHERE a.status = 1 AND a.typeid = :typeid")
List<Article> findPublishedByCategory(@Param("typeid") Integer typeid);
@Query("SELECT a FROM Article a WHERE a.status = 1 AND a.attributeid = :attributeid")
List<Article> findPublishedByAttribute(@Param("attributeid") Integer attributeid);
/**
* 根据属性ID查询最新的文章列表
* 使用JPQL查询语句筛选状态为已发布(status=1)且指定属性(attributeid)的文章,按创建时间降序排序
*
* @param attributeid 属性ID通过@Param注解映射到查询语句中的:attributeid参数
* @return 返回符合条件Article对象的列表按创建时间降序排列
*/
@Query("SELECT a FROM Article a WHERE a.status = 1 AND a.attributeid = :attributeid ORDER BY a.createdAt DESC")
List<Article> findLatestByAttribute(@Param("attributeid") Integer attributeid);
/**
* 使用@Modifying注解标记这是一个修改操作通常用于UPDATE或DELETE语句

View File

@@ -0,0 +1,46 @@
package com.qf.myafterprojecy.repository;
import com.qf.myafterprojecy.pojo.Category_attribute;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Optional;
@Repository
public interface CategoryAttributeRepository extends JpaRepository<Category_attribute, Integer> {
/**
* 根据分类ID查询分类属性列表
* @param categoryid 分类ID
* @return 返回该分类下的所有属性列表
*/
@Query("SELECT ca FROM Category_attribute ca WHERE ca.categoryid = :categoryid")
List<Category_attribute> findByCategoryId(@Param("categoryid") Integer categoryid);
/**
* 根据属性ID查询属性信息
* @param attributeid 属性ID
* @return 返回属性对象
*/
@Query("SELECT ca FROM Category_attribute ca WHERE ca.attributeid = :attributeid")
Optional<Category_attribute> findByAttributeId(@Param("attributeid") Integer attributeid);
/**
* 检查分类下是否存在指定名称的属性
* @param categoryid 分类ID
* @param attributename 属性名称
* @return 是否存在
*/
boolean existsByCategoryidAndAttributename(Integer categoryid, String attributename);
/**
* 根据分类ID和属性名称查询属性
* @param categoryid 分类ID
* @param attributename 属性名称
* @return 属性对象
*/
Optional<Category_attribute> findByCategoryidAndAttributename(Integer categoryid, String attributename);
}

View File

@@ -1,4 +1,6 @@
package com.qf.myafterprojecy.repository;
public interface Category_attribute {
import org.hibernate.metamodel.model.convert.spi.JpaAttributeConverter;
public interface Category_attribute extends JpaAttributeConverter<Category_attribute, Integer> {
}