1
0
mirror of https://gitee.com/bookshelfplus/bookshelfplus synced 2025-09-11 19:21:39 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee

查询所有分类后端完成

This commit is contained in:
2022-04-02 20:04:48 +08:00
parent 3320d7a90a
commit 60b76089e0
7 changed files with 89 additions and 43 deletions

View File

@@ -17,6 +17,9 @@ import plus.bookshelf.Service.Model.CategoryModel;
import plus.bookshelf.Service.Service.BookService;
import plus.bookshelf.Service.Service.CategoryService;
import java.util.ArrayList;
import java.util.List;
@Api(tags = "书籍分类信息")
@Controller("category")
@RequestMapping("/category")
@@ -25,7 +28,7 @@ public class CategoryController extends BaseController {
@Autowired
CategoryService categoryService;
@ApiOperation(value = "获取书籍分类", notes = "获取书籍分类")
@ApiOperation(value = "获取指定分类", notes = "获取指定的书籍分类")
@RequestMapping(value = "get", method = {RequestMethod.GET})
@ResponseBody
public CommonReturnType get(@RequestParam(value = "id") Integer id) {
@@ -38,6 +41,19 @@ public class CategoryController extends BaseController {
return CommonReturnType.create(categoryVO);
}
@ApiOperation(value = "获取所有分类", notes = "获取所有的书籍分类")
@RequestMapping(value = "list", method = {RequestMethod.GET})
@ResponseBody
public CommonReturnType getAll() {
List<CategoryModel> categoryModels = categoryService.getAllCategorys();
List<CategoryVO> categoryVOS = new ArrayList<>();
for (CategoryModel categoryModel : categoryModels) {
CategoryVO categoryVO = convertFromModel(categoryModel);
categoryVOS.add(categoryVO);
}
return CommonReturnType.create(categoryVOS);
}
private CategoryVO convertFromModel(CategoryModel categoryModel) {
if (categoryModel == null) {
return null;

View File

@@ -62,4 +62,6 @@ public interface CategoryDOMapper {
int updateByPrimaryKey(CategoryDO record);
CategoryDO[] selectChildrenByCategoryId(Integer id);
CategoryDO[] selectAll();
}

View File

@@ -7,12 +7,21 @@ import plus.bookshelf.Dao.Mapper.CategoryDOMapper;
import plus.bookshelf.Service.Model.CategoryModel;
import plus.bookshelf.Service.Service.CategoryService;
import java.util.ArrayList;
import java.util.List;
@Service
public class CategoryServiceImpl implements CategoryService {
@Autowired
private CategoryDOMapper categoryDOMapper;
/**
* 获取指定分类详情
*
* @param id
* @return
*/
@Override
public CategoryModel getCategoryById(Integer id) {
CategoryDO categoryDO = categoryDOMapper.selectByPrimaryKey(id);
@@ -31,6 +40,23 @@ public class CategoryServiceImpl implements CategoryService {
return categoryModel;
}
/**
* 取得所有分类
*
* @return
*/
@Override
public List<CategoryModel> getAllCategorys() {
CategoryDO[] categoryDOS = categoryDOMapper.selectAll();
List<CategoryModel> categoryModels = new ArrayList<>();
for (CategoryDO categoryDO : categoryDOS) {
CategoryModel categoryModel = convertFromDataObject(categoryDO);
categoryModels.add(categoryModel);
}
return categoryModels;
}
// 转换时不转换父亲与儿子,否则会陷入死循环
private CategoryModel convertFromDataObject(CategoryDO categoryDO) {
if (categoryDO == null) {

View File

@@ -2,6 +2,8 @@ package plus.bookshelf.Service.Service;
import plus.bookshelf.Service.Model.CategoryModel;
import java.util.List;
public interface CategoryService {
/**
* 通过分类Id获取分类
@@ -10,4 +12,11 @@ public interface CategoryService {
* @return
*/
CategoryModel getCategoryById(Integer id);
/**
* 获取所有的分类列表
*
* @return
*/
List<CategoryModel> getAllCategorys();
}