后台接口多参数接收,Page、Object以及List集合
①未选中人员时,导出所查询到的数据;
②选中人员时,导出选中人员数据;
可知接口需要接收过滤条件等参数,以及选中人员的ids集合,以及是否需要分页
// public ResponseObj<Page<SubjectEnrollDetail>> export(@RequestBody Page<SubjectEnrollDetail> page,
// @RequestBody SubjectEnrollDetail model,
// @RequestBody List<Long> ids) throws Exception {
刚开始想这么多参数怎么接收,像上面这样的肯定不行了。既然要接收ids集合,当选中的人员很多时,如果使用GET请求方式肯定爆了,url就会很长,有可能超过限制长度,导致后台接收失败。所以只能使用POST请求方式application/json,那么参数接收就显而易见了,使用(@RequestBody Map map)
public ResponseObj<Page<SubjectEnrollDetail>> export(@RequestBody Map map) throws Exception {
}
postman传的参数
postman传的参数.png其中,ids是一个int类型数组,被后台接收之后是Integer类型
image.png /**
* 导出
* @param map
* @return
* @throws Exception
*/
@RequestMapping(value = "/export", method = RequestMethod.POST)
public ResponseObj<Page<SubjectEnrollTicketDetail>> export(@RequestBody Map map) throws Exception {
Page page = new Page();
List<Long> list = (List<Long>) map.get("ids");
Integer current = (Integer) map.get("current");
Integer size = (Integer) map.get("size");
if (list != null && list.size() > 0) {
if (current != null && size != null) {
page.setCurrent(current);
page.setSize(size);
} else {
page.setCurrent(1);
page.setSize(list.size());
}
}
if (current != null && size != null) {
page.setCurrent(current);
page.setSize(size);
}
Page<SubjectEnrollTicketDetail> pageList;
SubjectEnrollTicketDetail model = (SubjectEnrollTicketDetail) MapBeanUtil.mapToBean(map, SubjectEnrollTicketDetail.class);
if (list != null && list.size() > 0) {
pageList = serviceDetail.selectPage(page, new EntityWrapper<>(model).in("id", list));
} else {
pageList = serviceDetail.selectPage(page, new EntityWrapper<>(model));
}
return new ResponseObj<>(pageList, RetCode.SUCCESS);
}
这个接口只是返回数据给前端,如果想后台生成excel的话,参考
导出接口生成excel
网友评论