mirror of
https://gitee.com/bookshelfplus/bookshelfplus
synced 2025-09-17 23:46:12 +08:00
查询所有分类后端完成
This commit is contained in:
@@ -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) {
|
||||
|
Reference in New Issue
Block a user