要根据"tid"列区分结果并获得唯一的结果集,您可以使用一个集在迭代数据集结果时跟踪唯一的tid值.以下是修改代码以实现这一点的方法:
Page<Object[]> datasetresults = repository.findtest(tid, PageRequest.of(page, per_page, Sort.by(s, sort)));
// Create a Set to keep track of unique tid values
Set<Long> uniqueTids = new HashSet<>();
for (Object[] object : datasetresults.getContent()) {
if (object[0] instanceof onetable && object[1] instanceof twotable) {
onetable onetable = (onetable) object[0];
twotable twotable = (twotable) object[1];
// Check if the tid is unique
if (uniqueTids.add(onetable.getTid())) {
// This tid is unique, process the result
TestBean test = new TestBean();
// Add your code here to process the unique result
}
}
}
在这段代码中,我们使用一个名为Unique eTids的集合来跟踪唯一的"tid"值.在处理每个结果之前,我们使用Unique eTids.add(onetable.getTid())判断"tid"是否已经在集合中.如果是新的"TID",我们会处理结果.这确保只处理唯一的"tid"值,从而根据"tid"提供不同的结果集.