使用mybatis-plus查询时,当查询的条件在model中时,model放入括号内new EntityWrapper<>(model)
/**
* 返回列表
*
* @return
*/
@RequestMapping(value = "/list", method = RequestMethod.GET)
public ResponseObj<List<SubjectEnrollCertList>> list(@ModelAttribute SubjectEnrollCertList model) throws Exception {
List<SubjectEnrollCertList> listModel = serviceList.selectList(queryWrapper(new EntityWrapper<>(model)));
for (SubjectEnrollCertList eachObj : listModel) {
queryFilter(eachObj);
}
return new ResponseObj<>(listModel, RetCode.SUCCESS);
}
/**
* 导出:可以单个导出,可以多个或者全部导出
* 分已发放和未发放导出
*
* @param map
* @return
* @throws Exception
*/
@RequestMapping(value = "/export", method = RequestMethod.POST)
public ResponseObj<Page<SubjectEnrollCertDetail>> export(@RequestBody Map map) throws Exception {
Page page = new Page();
List<Long> list = (List<Long>) map.get("ids");
Boolean isnull = (Boolean) map.get("isnull");
SubjectEnrollCertDetail model = (SubjectEnrollCertDetail) MapBeanUtil.mapToBean(map,
SubjectEnrollCertDetail.class);
List<SubjectEnrollCertDetail> detailList;
if (isnull) { //未发放
if (list != null && list.size() > 0) {
detailList = serviceDetail.selectList(new EntityWrapper<>(model).in("eid", list).isNull(true, "id"));
page.setRecords(detailList);
} else {
detailList = serviceDetail.selectList(new EntityWrapper<>(model).isNull(true, "id"));
page.setRecords(detailList);
}
} else { //已发放
if (list != null && list.size() > 0) {
detailList = serviceDetail.selectList(new EntityWrapper<>(model).in("id", list).isNotNull(true, "id"));
page.setRecords(detailList);
} else {
detailList = serviceDetail.selectList(new EntityWrapper<>(model).isNotNull(true, "id"));
page.setRecords(detailList);
}
}
return new ResponseObj<>(page, RetCode.SUCCESS);
}
使用mybatis-plus查询时,当查询的条件不在model中时,需要自定义时候,model放入尖括号内new EntityWrapper<AuthBatchSubject>().in("batchid", ids)
/**
* 批量删除
*/
@Override
@Transactional(rollbackFor = Exception.class)
public ResponseObj<Boolean> delList(@RequestBody List<Long> ids) throws Exception {
if (ids == null || ids.size() <= 0) {
return new ResponseObj<>(false, RetCode.NODATA);
}
boolean result = service.deleteBatchIds(ids);
boolean batchid = batchSubjectService.delete(new EntityWrapper<AuthBatchSubject>().in("batchid", ids));
if (result && batchid)
return new ResponseObj<>(true, RetCode.SUCCESS);
return new ResponseObj<>(false, RetCode.FAIL);
}
使用mybatis-plus查询时,也可以都不传,那就是查询所有结果了
/**
* 设置当前批次开关
*/
@RequestMapping(value = "/setCurrentBatch", method = RequestMethod.GET)
public ResponseObj<Boolean> setCurrentBatch(@RequestParam Long batchid) throws Exception {
// 0 关闭 1开启
AuthBatchManage1 authBatchManage = new AuthBatchManage1();
authBatchManage.setIsClose(1);
boolean isClose = authBatchManageService1.update(authBatchManage, new EntityWrapper<>());
authBatchManage.setIsClose(0);
authBatchManage.setId(batchid);
boolean b = authBatchManageService1.updateById(authBatchManage);
if (isClose && b) {
return new ResponseObj<>(true, RetCode.SUCCESS);
} else {
return new ResponseObj<>(true, RetCode.SUCCESS);
}
}
网友评论