API自定义查询条件
如果不想使用数据字典配置,可通过配置API地址实现查询条件配置,配置方法如下:
1、后台需要准备的数据
- 1)需要get请求数据接口,返回数据JSON格式如下:
[
{
"text": "男",
"value": "1"
},
{
"text": "女",
"value": "2"
}
]
1.7.9+版本
注意:在1.9.2+版本之后,在页面初始化的时候,如果你设置了默认值,系统将会传递
initValue
参数,多个以逗号拼接,你需要根据当前的value值返回对应的字典项

/**
* 返回数据字典
*
* @param dictCode 字典值code(是报表动态报表配置明细的字段名称)
* @param pageNo 当前页数
* @param pageSize 每页显示条数
* @param searchText 搜索文本
* @param queryAll 查询全部,当queryAll为true的时候需要将所有字典值返回,否则会影响列表字典的翻译
* @param initValue 字典初始化的时候查询的默认值(在报表设计中设置了默认值时才会传递)
*/
@GetMapping("/getDictSex")
public List<Object> getDictSex(@RequestParam(name="dictCode") String dictCode,
@RequestParam(name = "pageNo",defaultValue = "1",required = false) Integer pageNo,
@RequestParam(name = "pageSize",defaultValue = "10",required = false) Integer pageSize,
@RequestParam(name="searchText",required = false) String searchText,
@RequestParam(name="queryAll",required = false) Boolean queryAll,
@RequestParam(name = "initValue", required = false) String initValue){
List<Object> list = new ArrayList<>();
if("sex".equals(dictCode)){
for (int i = 0; i < 12; i++) {
Map<String,String> map = new HashMap<>(5);
map.put("text","男"+i);
map.put("value","1"+i);
list.add(map);
}
}
if("男".equals(searchText)){
List<Object> list1 = new ArrayList<>();
Map<String,String> map = new HashMap<>(5);
map.put("text","男");
map.put("value","1");
list1.add(map);
return list1;
}
if(pageNo >=2){
return new ArrayList<>();
}
return list;
}
1.7.9及1.7.9以下版本
/**
* 返回数据字典
* @param dictCode 字典值code(是报表动态报表配置明细的字段名称)
*/
@GetMapping("/getDictSex")
public List getDictSex(@RequestParam(name="dictCode") String dictCode){
List list = new ArrayList<>();
if(dictCode.equals("sex")){
Map map = new HashMap<>();
map.put("text","男");
map.put("value","1");
list.add(map);
Map map1 = new HashMap<>();
map1.put("text","女");
map1.put("value","2");
list.add(map1);
}
return list;
}
- 2)动态传参
如何传递系统变量,可以通过#参数,如
?createBy=#{自定义的系统变量}
2、前台需要做的配置
点开api数据集或sql数据集,在报表字段明细
或报表参数
中找到要配置的字段,将API地址添加到“字典code”中,勾选“查询”,“查询模式”选择为“多选查询”或“单选查询”即可;
注:如果为外部路径则需要加http或https全路径;如果不加则默认为相对路径,系统自动配置ip及项目名
示例1: 相对路径
/jmreport/test/getDictSex?createBy=#{sysUserCode}
示例2: 全路径
http://127.0.0.1:8080/jeecg-boot/jmreport/test/getDictSex?createBy=#{sysUserCode}