老师为什么不给出这样的数据结构而是给出两个列表数据,既不方便前端理解,又不方便前端使用

老师为什么不给出这样的数据结构而是给出两个列表数据,既不方便前端理解,又不方便前端使用

[

    {

        "id": 1,

        "name": "鞋",

        "description": null,

        "is_root": true,

        "parent_id": null,

        "img": "http://i2.sleeve.7yue.pro/u2.png",

        "index": 3,

        "online": 1,

        "level": null,

        "items": [

            {

                "id": 6,

                "name": "平底鞋",

                "description": null,

                "is_root": false,

                "parent_id": 1,

                "img": "http://i2.sleeve.7yue.pro/u4.png",

                "index": null,

                "online": 1,

                "level": null

            },

            {

                "id": 7,

                "name": "凉鞋",

                "description": null,

                "is_root": false,

                "parent_id": 1,

                "img": "http://i2.sleeve.7yue.pro/u5.png",

                "index": null,

                "online": 1,

                "level": null

            },

            {

                "id": 8,

                "name": "拖鞋",

                "description": null,

                "is_root": false,

                "parent_id": 1,

                "img": "http://i2.sleeve.7yue.pro/u6.png",

                "index": null,

                "online": 1,

                "level": null

            },

            {

                "id": 9,

                "name": "运动鞋",

                "description": null,

                "is_root": false,

                "parent_id": 1,

                "img": "http://i2.sleeve.7yue.pro/u4.png",

                "index": null,

                "online": 1,

                "level": null

            },

            {

                "id": 10,

                "name": "高跟鞋",

                "description": null,

                "is_root": false,

                "parent_id": 1,

                "img": "http://i2.sleeve.7yue.pro/u5.png",

                "index": null,

                "online": 1,

                "level": null

            }

        ]

    },

    {

        "id": 2,

        "name": "服装",

        "description": null,

        "is_root": true,

        "parent_id": null,

        "img": "http://i2.sleeve.7yue.pro/u3.png",

        "index": 2,

        "online": 1,

        "level": null,

        "items": [

            {

                "id": 11,

                "name": "衬衫",

                "description": null,

                "is_root": false,

                "parent_id": 2,

                "img": "http://i2.sleeve.7yue.pro/u5.png",

                "index": null,

                "online": 1,

                "level": null

            },

            {

                "id": 12,

                "name": "T恤",

                "description": null,

                "is_root": false,

                "parent_id": 2,

                "img": "http://i2.sleeve.7yue.pro/u4.png",

                "index": null,

                "online": 1,

                "level": null

            },

            {

                "id": 13,

                "name": "牛仔裤",

                "description": null,

                "is_root": false,

                "parent_id": 2,

                "img": "http://i2.sleeve.7yue.pro/u5.png",

                "index": null,

                "online": 1,

                "level": null

            },

            {

                "id": 14,

                "name": "针织衫",

                "description": null,

                "is_root": false,

                "parent_id": 2,

                "img": "http://i2.sleeve.7yue.pro/u6.png",

                "index": null,

                "online": 1,

                "level": null

            },

            {

                "id": 15,

                "name": "连衣裙",

                "description": null,

                "is_root": false,

                "parent_id": 2,

                "img": "http://i2.sleeve.7yue.pro/u6.png",

                "index": null,

                "online": 1,

                "level": null

            },

            {

                "id": 16,

                "name": "风衣",

                "description": null,

                "is_root": false,

                "parent_id": 2,

                "img": "http://i2.sleeve.7yue.pro/u5.png",

                "index": null,

                "online": 1,

                "level": null

            }

        ]

    },

    {

        "id": 3,

        "name": "包包",

        "description": null,

        "is_root": true,

        "parent_id": null,

        "img": "http://i2.sleeve.7yue.pro/u3.png",

        "index": 1,

        "online": 1,

        "level": null,

        "items": [

            {

                "id": 17,

                "name": "手包",

                "description": null,

                "is_root": false,

                "parent_id": 3,

                "img": "http://i2.sleeve.7yue.pro/u6.png",

                "index": null,

                "online": 1,

                "level": null

            },

            {

                "id": 18,

                "name": "旅行包",

                "description": null,

                "is_root": false,

                "parent_id": 3,

                "img": "http://i2.sleeve.7yue.pro/u4.pn",

                "index": null,

                "online": 1,

                "level": null

            },

            {

                "id": 19,

                "name": "单肩包",

                "description": null,

                "is_root": false,

                "parent_id": 3,

                "img": "http://i2.sleeve.7yue.pro/u5.png",

                "index": null,

                "online": 1,

                "level": null

            }

        ]

    },

    {

        "id": 4,

        "name": "居家",

        "description": null,

        "is_root": true,

        "parent_id": null,

        "img": "http://i2.sleeve.7yue.pro/u2.png",

        "index": 5,

        "online": 1,

        "level": null,

        "items": [

            {

                "id": 20,

                "name": "收纳",

                "description": null,

                "is_root": false,

                "parent_id": 4,

                "img": "http://i2.sleeve.7yue.pro/u4.png",

                "index": null,

                "online": 1,

                "level": null

            },

            {

                "id": 21,

                "name": "毛巾",

                "description": null,

                "is_root": false,

                "parent_id": 4,

                "img": "http://i2.sleeve.7yue.pro/u5.png",

                "index": null,

                "online": 1,

                "level": null

            },

            {

                "id": 22,

                "name": "四件套",

                "description": null,

                "is_root": false,

                "parent_id": 4,

                "img": "http://i2.sleeve.7yue.pro/u6.png",

                "index": null,

                "online": 1,

                "level": null

            },

            {

                "id": 23,

                "name": "台灯",

                "description": null,

                "is_root": false,

                "parent_id": 4,

                "img": "http://i2.sleeve.7yue.pro/u4.png",

                "index": null,

                "online": 1,

                "level": null

            }

        ]

    },

    {

        "id": 5,

        "name": "饰品",

        "description": null,

        "is_root": true,

        "parent_id": null,

        "img": "http://i2.sleeve.7yue.pro/u2.png",

        "index": 4,

        "online": 1,

        "level": null,

        "items": [

            {

                "id": 36,

                "name": "酷玩",

                "description": null,

                "is_root": false,

                "parent_id": 5,

                "img": "http://i2.sleeve.7yue.pro/u5.png",

                "index": null,

                "online": 1,

                "level": null

            },

            {

                "id": 39,

                "name": "束带",

                "description": null,

                "is_root": false,

                "parent_id": 5,

                "img": "http://i2.sleeve.7yue.pro/u4.png",

                "index": null,

                "online": 1,

                "level": null

            }

        ]

    },

    {

        "id": 24,

        "name": "工艺",

        "description": null,

        "is_root": true,

        "parent_id": null,

        "img": "http://i2.sleeve.7yue.pro/u3.png",

        "index": 1,

        "online": 1,

        "level": null,

        "items": [

            {

                "id": 32,

                "name": "文具",

                "description": null,

                "is_root": false,

                "parent_id": 24,

                "img": "http://i2.sleeve.7yue.pro/u6.png",

                "index": null,

                "online": 1,

                "level": null

            }

        ]

    },

    {

        "id": 37,

        "name": "测试数据",

        "description": null,

        "is_root": true,

        "parent_id": null,

        "img": "http://i2.sleeve.7yue.pro/u2.png",

        "index": null,

        "online": 1,

        "level": null,

        "items": [

            {

                "id": 38,

                "name": "测试数据",

                "description": null,

                "is_root": false,

                "parent_id": 37,

                "img": "http://i2.sleeve.7yue.pro/u5.png",

                "index": null,

                "online": 1,

                "level": null

            }

        ]

    }

]

正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

2回答
7七月 2020-03-14 07:40:34

前端这里处理的时候是 函数式编程,服务端stream 一模一样的处理。所以 这是等成本的。

7七月 2020-03-14 07:31:48

因为不想写这些 没有技术含量的处理。写了要讲,讲了又浪费时间。如果你想的话,自己在服务端处理。不然留给前端处理。

另外,为什么要服务端处理,同等业务,前端不能处理吗?反正都要解析一遍,放前端还能节约点服务端性能。

  • 提问者 Kely_Developer #1
    因为对于导航属性我还有很多疑惑,例如这里的某个一级分类下包含的二级分类我们可以通过导航属性很轻松的获得,但是如果我们需要给对应的二级分类按照某个条件查询 某个规则排序等 这样该如何处理呢
    2020-03-14 08:25:36
  • 7七月 回复 提问者 Kely_Developer #2
    你说的这个二级分类的筛选一样可以用JPA的命名方法
    2020-03-14 23:04:20
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师