要求:
查询出来的时候一个资质表中有多个计划事项
实现结果:
思路:
* 先建立好需要的数据库表以及实体类 * 建一个VO 放入List资质台账集合 * 查询资质台账集合 * 查询计划事项集合 * 遍历计划事项集合 * 将计划事项集合添加到资质台账中
具体代码逻辑如下:
@RestController
@RequestMapping("/quAccount")
@Api(value = "资质台账", tags = "资质台账")
public class QuAccountController extends BaseController {
@Autowired
private QuAccountService quAccountService;
@Autowired
private PlanIssuesService planIssuesService;
@RequestMapping(value = "/page" , method = RequestMethod.GET)
@ApiOperation(value = "分页查询", httpMethod = "Get")
public TableDataInfo pageAll(@RequestBody QuAccountBO.Page quAccountBO){
startPage(quAccountBO);
List list = quAccountService.list();
List quAccountVOS = list.stream().map(this::cover).collect(Collectors.toList());
for (QuAccountVO quAccountVO : quAccountVOS) {
LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>();
wrapper.eq(PlanIssuesPO::getQuAccountId ,quAccountVO.getId());
List planIssuesPOS = planIssuesService.list(wrapper);
quAccountVO.setPlanIssuesPOS(planIssuesPOS);
}
// bean复制属性后,总条数固定为请求条数,设置total
TableDataInfo dataTable = getDataTable(quAccountVOS);
dataTable.setTotal(list.size());
return dataTable;
}
public QuAccountVO cover(QuAccountPO quAccountPO) {
QuAccountVO quAccountVO = new QuAccountVO();
BeanUtils.copyProperties(quAccountPO,quAccountVO);
return quAccountVO;
}
}
查询出来之后,还可以使用Wrapper方法来实现模糊查询
只需要对以上代码稍微改动
BO代码如下:
public class QuAccountBO extends QuAccountPO {
@Data
@ApiModel(value = "资质台账id" , description = "根据id显示相应的资质台账数据")
public static class Page extends PageRequest{
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "id",required = true)
private Integer id;
@ApiModelProperty(value = "资质类别",required = true)
private String category;
}
}
VO代码如下:
@Data
public class QuAccountVO extends QuAccountPO {
private List planIssuesPOS;
}
代码如下:
public TableDataInfopageAll(@RequestBody QuAccountBO.Page quAccountBO){ startPage(quAccountBO); //根据资质类别模糊查询 List list = quAccountService.list( Wrappers. lambdaQuery() .like(StringUtils.isNotEmpty(quAccountBO.getCategory()),QuAccountPO::getCategory,quAccountBO.getCategory()) ); List quAccountVOS = list.stream().map(this::cover).collect(Collectors.toList()); for (QuAccountVO quAccountVO : quAccountVOS) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.eq(PlanIssuesPO::getQuAccountId ,quAccountVO.getId()); List planIssuesPOS = planIssuesService.list(wrapper); quAccountVO.setPlanIssuesPOS(planIssuesPOS); } // bean复制属性后,总条数固定为请求条数,设置total TableDataInfo dataTable = getDataTable(quAccountVOS); dataTable.setTotal(list.size()); return dataTable; }
以上只是自己的写法,具体写法还有很多。



