系统表单
非分页数据源
可用于明细表/下拉框/数据映射API数据源
明细表数据源和下拉框数据源都是不分页的数据结构,要求API返回一个ZcResult结构,且其中的data为一个List,通常情况下使用下面这种结构:
数据结构
{
"success": true,
"code": "00000",
"message": null,
"data": [
{
"字段1": "字段值1",
"字段2": "字段值2",
}
]
}
后台代码
@GetMapping("getDatasourceRepeatTable")
public ZcResult<List<Product>> getDatasourceRepeatTable() {
// 创建返回结构
ZcResult zcResult = ZcResult.success();
// 设置状态码
zcResult.setCode("000000");
// 这一步取了product表中的所有数据,此逻辑根据具体需要修改,此处是查询了表中的所有数据
List<Product> list = productService.queryAll();
// 设置数据
zcResult.setData(list);
// 设置消息
zcResult.setMessage("");
// 返回
return zcResult;
}
分页数据源
适用于选择数据组件的动态数据源
数据结构
{
"success": true,
"code": "00000",
"message": null,
"data": {
"index": 1,
"size": 10,
"total": "100",
"rows": [
{
"id": 1,
"字段1": "字段1",
}
]
}
}
后台代码
@PostMapping("pager")
public ZcPageResult<Product> pager(@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;
}
}