easymall----管理后端分类展示

目的效果

建表思路:categoryId是必须的 标识产品本身 因为是树形结构需要与父id联动 所以需要 pcategoryId 产品本身需要名字 所以需要 category_name

所以最基础的字段只需要这三个

表格展示:

sort字段为额外功能 可以通过前端拖动进行人为的排序 可加可不加

controller层:

复制代码
@RequestMapping("/loadCategory")
public ResponseVO loadCategory(){
    SysCategoryQuery sysCategoryQuery = new SysCategoryQuery();
    sysCategoryQuery.setOrderBy("s.sort asc");
    return getSuccessResponseVO(sysCategoryService.findListByParam(sysCategoryQuery));
}

实现层:

复制代码
@Override
public List<SysCategory> findListByParam(SysCategoryQuery param) {
    List<SysCategory> sysCategoryList = this.sysCategoryMapper.selectList(param);
 
    sysCategoryList = convertLine2Tree(sysCategoryList, Constants.ZERO_STR);
    
    return sysCategoryList;

}
private List<SysCategory> convertLine2Tree(List<SysCategory> dataList, String pid) {
    List<SysCategory> children = new ArrayList();
    for (SysCategory m : dataList) {
       if (m.getCategoryId() != null && m.getpCategoryId() != null && m.getpCategoryId().equals(pid)) {
          m.setChildren(convertLine2Tree(dataList, m.getCategoryId()));
          children.add(m);
       }
    }
    return children;
}

这部分需要细讲,要如图展示需要人为对类进行改造,要给sysCategory类加上List<sysCategory> children属性,便于树形展示 convertLine2Tree对查找到的所有数据进行递归 将子分类加入到children中

最后返回(小部分内容):

{

"status": "success",

"code": 200,

"info": "请求成功",

"data": [

{

"categoryId": "10001",

"categoryName": "数码家电",

"pCategoryId": "0",

"sort": 1,

"children": [

{

"categoryId": "20001",

"categoryName": "手机通讯",

"pCategoryId": "10001",

"sort": 1,

"children": \[\]

},

{

"categoryId": "20002",

"categoryName": "电脑办公",

"pCategoryId": "10001",

"sort": 2,

"children": \[\]

},

{

"categoryId": "20003",

"categoryName": "数码影音",

"pCategoryId": "10001",

"sort": 3,

"children": \[\]

},

{

"categoryId": "20004",

"categoryName": "家用电器",

"pCategoryId": "10001",

"sort": 4,

"children": \[\]

}

]

}

}

相关推荐
未来之窗软件服务13 小时前
web网络请求竞态问题与取消方案-东方仙盟
前端·状态模式·仙盟创梦ide·东方仙盟·网络取消
一级新生2 天前
多智能体协作:常用协作模式详解
人工智能·状态模式·agent·多智能体·智能体
喜欢打篮球的普通人3 天前
LLVM 前端与优化层:Clang 如何把 C 代码变成 IR
c语言·前端·状态模式
m0_敲代码的彭于晏1684 天前
Vercel 前端部署与全栈开发实战指南
前端·状态模式
星恒随风5 天前
Linux线程同步与互斥(二):从日志系统与线程池设计,到线程安全单例、可重入函数和死锁原理
linux·运维·状态模式
学Linux的语莫5 天前
python中类的常见写法
开发语言·python·状态模式
223糖5 天前
Tool Calling 是什么?用后端接口的思路讲清楚
状态模式
染指11107 天前
151.Agent-LangGraph-Send发送(Map-Reduce模式)
人工智能·python·langchain·状态模式·agents
鸽鸽程序猿8 天前
【项目】【在线判题系统】竞赛发布与撤销发布
状态模式
lemon_sjdk9 天前
从一段真实的 Electron IM 前端代码,看高级前端的工程化修养
前端·electron·状态模式·im