一、场景说明
后端需要接收多条数据实现批量绑定的效果,如果按照定义bean的话,实际上是一个List<Param>结构,我们情况看Postman的请求参数.
[{
"elementId" : "9212066927850701332",
"dataId" : "-211208903950905634_4",
"metadata" : {
"uuid": "67947291-6b27-4371-8d64-4db3c695cb65",
"sign": "FLow",
"attributes": {
"formId": 414564057231344759,
"bizId": -6115980305565398932,
"state": 4,
"templateId": -211208903950905634
}
}
}]
二、定义后端参数Param对象
public class ElementDataSetBinding implements Serializable {
/**
* 元素Id
*/
private Long elementId;
/**
* 数据集Id
*/
private String dataId;
/**
* 数据集元信息
*/
private DataSetMetadata metadata;
}
三、Rest接口定义
@Path("{configId}/section/{sectionId}/datasource/bind")
@POST
public Response bindDataSet(@PathParam("bizId") Long bizId,
@PathParam("configId") Long configId,
@PathParam("sectionId") Long sectionId,
ElementDataSetBinding[] bindings) {
return success(getBizPortalService().bindDataSet(bizId, configId, sectionId, bindings));
}
四、总结
- 对于requestBody有了更深的认识,以前一直以为只能传递{}这类的数据格式,实际上还可以传递[]数组格式的.
- 多试,多犯错,才能有更大的成长。