refactor(pojo): 修正Article类中attributeid字段的列名拼写

feat(controller): 在ArticleController中添加根据属性ID获取文章的方法

style(repository): 在CategoryRepository方法上添加空行提高可读性

chore: 移除MyAfterProjecyApplication中多余的MapperScan注解
This commit is contained in:
qingfeng1121
2025-10-19 11:11:56 +08:00
parent bd6b240f52
commit effcc3838d
8 changed files with 457 additions and 61 deletions

View File

@@ -1,6 +1,5 @@
package com.qf.myafterprojecy;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

View File

@@ -52,6 +52,47 @@ public class ArticleController {
return articleService.getArticlesByTitle(title);
}
/**
* 根据属性ID获取该属性下的所有文章
* @param attributeId 属性ID
* @return 返回包含文章列表的ResponseMessage对象
*/
@GetMapping("/attribute/{attributeId}")
public ResponseMessage<List<Article>> getArticlesByAttribute(@PathVariable Integer attributeId) {
return articleService.getArticlesByAttribute(attributeId);
}
/**
* 根据分类ID获取该分类下的所有文章兼容旧接口
* @param categoryId 分类ID
* @return 返回包含文章列表的ResponseMessage对象
*/
@GetMapping("/category/{categoryId}")
public ResponseMessage<List<Article>> getArticlesByCategory(@PathVariable Integer categoryId) {
return articleService.getArticlesByCategory(categoryId);
}
/**
* 根据属性ID获取最新文章按创建时间降序
* @param attributeId 属性ID
* @return 返回包含最新文章列表的ResponseMessage对象
*/
@GetMapping("/attribute/{attributeId}/latest")
public ResponseMessage<List<Article>> getLatestArticlesByAttribute(@PathVariable Integer attributeId) {
return articleService.getLatestArticlesByAttribute(attributeId);
}
/**
*
* @return ar
*/
/**
* 获取浏览量最高的文章列表
* @return 返回包含热门文章列表的ResponseMessage对象
*/
@GetMapping("/popular")
public ResponseMessage<List<Article>> getMostViewedArticles() {
return articleService.getMostViewedArticles();
}
/**
* 创建新文章
* 仅限AUTHOR角色用户访问
@@ -91,43 +132,4 @@ public class ArticleController {
return articleService.deleteArticle(id);
}
/**
* 根据分类ID获取该分类下的所有文章兼容旧接口
* @param categoryId 分类ID
* @return 返回包含文章列表的ResponseMessage对象
*/
@GetMapping("/category/{categoryId}")
public ResponseMessage<List<Article>> getArticlesByCategory(@PathVariable Integer categoryId) {
return articleService.getArticlesByCategory(categoryId);
}
/**
* 根据属性ID获取该属性下的所有文章
* @param attributeId 属性ID
* @return 返回包含文章列表的ResponseMessage对象
*/
@GetMapping("/attribute/{attributeId}")
public ResponseMessage<List<Article>> getArticlesByAttribute(@PathVariable Integer attributeId) {
return articleService.getArticlesByAttribute(attributeId);
}
/**
* 根据属性ID获取最新文章按创建时间降序
* @param attributeId 属性ID
* @return 返回包含最新文章列表的ResponseMessage对象
*/
@GetMapping("/attribute/{attributeId}/latest")
public ResponseMessage<List<Article>> getLatestArticlesByAttribute(@PathVariable Integer attributeId) {
return articleService.getLatestArticlesByAttribute(attributeId);
}
/**
* 获取浏览量最高的文章列表
* @return 返回包含热门文章列表的ResponseMessage对象
*/
@GetMapping("/popular")
public ResponseMessage<List<Article>> getMostViewedArticles() {
return articleService.getMostViewedArticles();
}
}

View File

@@ -33,6 +33,7 @@ public class CategoryAttributeController {
log.info("接收根据ID获取分类属性的请求: ID={}", id);
return categoryAttributeService.getCategoryAttributeById(id);
}
/**
* 根据分类ID获取属性列表

View File

@@ -22,7 +22,7 @@ public class Article {
private String content;
@NotNull(message = "类别id不能为空")
@Column(name = "attributeid")
@Column(name = "attribute_id")
private Integer attributeid;
@Column(name = "img")

View File

@@ -14,6 +14,9 @@ public class ArticleDto {
@NotBlank(message = "内容不能为空")
private String content;
@NotNull(message = "属性ID不能为空")
private Integer attributeid;
private String img;

View File

@@ -14,6 +14,7 @@ public interface CategoryRepository extends JpaRepository<Category, Integer> {
* @param typename 分类名称
* @return 返回符合条件的分类列表
*/
List<Category> findByTypenameContaining(String typename);
/**