Commit d04558c0 by 段启岩

博客分类接口

parent 41e90fea
......@@ -8,6 +8,7 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
......@@ -33,7 +34,14 @@ public class BlogCategoryApi {
@ApiOperation("获取博客分类")
@GetMapping("/blog/categories")
public Response<List<BlogCategory>> getBlogCategories () {
return Response.success(blogCategoryService.getBlogCategory());
return Response.success(blogCategoryService.getBlogCategory(null));
}
@Anonymous
@ApiOperation("获取博客子分类")
@GetMapping("/blog/{categoryId}/categories")
public Response<List<BlogCategory>> getBlogSubCategories (@PathVariable("categoryId") Integer categoryId) {
return Response.success(blogCategoryService.getBlogCategory(categoryId));
}
}
......@@ -18,6 +18,7 @@ public interface IBlogCategoryService extends IService<BlogCategory> {
/**
* 获取博客分类列表
* @return
* @param categoryId
*/
List<BlogCategory> getBlogCategory();
List<BlogCategory> getBlogCategory(Integer categoryId);
}
......@@ -21,10 +21,14 @@ import java.util.List;
public class BlogCategoryServiceImpl extends ServiceImpl<BlogCategoryMapper, BlogCategory> implements IBlogCategoryService {
@Override
public List<BlogCategory> getBlogCategory() {
public List<BlogCategory> getBlogCategory(Integer categoryId) {
//只获取第一层分类
QueryWrapper<BlogCategory> blogCategoryQueryWrapper = new QueryWrapper<>();
if (null == categoryId) {
blogCategoryQueryWrapper.isNull(true, "parent_id");
} else {
blogCategoryQueryWrapper.eq("parent_id", categoryId);
}
blogCategoryQueryWrapper.orderByDesc("priority");
blogCategoryQueryWrapper.orderByAsc("category_id");
List<BlogCategory> blogCategoryList = list(blogCategoryQueryWrapper);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment