1
0
mirror of https://gitee.com/bookshelfplus/bookshelfplus synced 2025-09-17 23:46:12 +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

@@ -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) {