系统视图
分页数据源
数据表格/数据列表/选择数据 API数据源
数据结构
数据表格需要一个分页的数据结构,外层需要通过ZcResult包装,返回给数据表格。
data中需要包含 index、size、total、rows,其中:
- rows为数据列表
 - index为当前页码
 - size为每页数据量
 - total为数据总量
 
{
    "success": true,
    "code": "00000",
    "message": null,
    "data": {
        "index": 1,
        "size": 20,
        "total": "100",
        "rows": [
            {
                "字段名称": "字段值",
                "字段名称2": "字段值2"
            }
        ]
    }
}
后台代码
@PostMapping("data_table_pager")
public ZcPageResult<Product> dataTablePager(@RequestParam(defaultValue = "1") String index, @RequestParam String size) {
    try {
        // 将字符串参数转换为长整型
        long indexLong = Long.parseLong(index);
        long sizeLong = Long.parseLong(size);
        // 验证分页参数是否有效
        if (indexLong <= 0 || sizeLong <= 0) {
            throw new IllegalArgumentException("分页参数无效");
        }
        ZcPageResult<Product> zcPageResult = new ZcPageResult<>();
        // 分页对象
        Page<Product> page = new Page<>(indexLong, sizeLong);
        // 分页的条件
        QueryWrapper<Product> queryWrapper = new QueryWrapper<>();
        // 设置一个查询条件,相对于where语句,proName字段不能为ACX(这个地方的column应该和数据库字段名称一致)
        queryWrapper.ne("pro_name", "ACX");
        // 执行查询
        IPage<Product> pageResult = productDao.selectPage(page, queryWrapper);
        // 设置分页结果
        zcPageResult.setRows(pageResult.getRecords());
        zcPageResult.setTotal(pageResult.getTotal());
        zcPageResult.setIndex((int) pageResult.getCurrent());
        zcPageResult.setSize((int) pageResult.getSize());
        return zcPageResult;
    } catch (NumberFormatException e) {
        // 处理参数转换异常
        throw new IllegalArgumentException("参数转换错误,无法识别的分页参数", e);
    } catch (IllegalArgumentException e) {
        throw e;
    }
}
数据树
数据树的请求并非一次将数据全部取回,而是根据点击的项标识获取下一级数据。因此会触发多次请求,数据格式亦为ZcPageResult对象(分页格式),但会以size 999的方式请求,以一次性获取目标所有的节点数据。
数据结构中需要包含当前节点的key以及父节点的key,其中,标识字段填写当前节点的key,父级字段填写父级节点的key,标题字段填写当前节点的标题。
顶点数据结构
{
    "success": true,
    "code": "00000",
    "message": null,
    "data": {
        "index": 1,
        "size": 999,
        "total": "1",
        "rows": [
            {
                "key": "0",
                "name":"一级节点",
                "parent_key": "",
            }
        ]
    }
}
子节点数据结构
{
    "success": true,
    "code": "00000",
    "message": null,
    "data": {
        "index": 1,
        "size": 999,
        "total": "1",
        "rows": [
            {
                "key": "0-0",
                "name":"二级节点 1",
                "parent_key": "0",
            },
            {
                "key": "0-1",
                "name":"二级节点 2",
                "parent_key": "0",
            }
        ]
    }
}