我有以下代码用于从多个表中检索数据(使用连接),然后将每一行映射到 DTOList 但我还需要根据用户首选项应用过滤器:每个 table1.name 或 table2.name、table3 等.所以我只想知道在性能和最佳实践方面最好的方法是什么;检索所有行,然后使用 lambda 应用过滤器(更简单)使用 Criteria 或其他方式将查询更改为动态查询?任何其他解决方案=?@Repositorypublic class ArchiveRepository { @Autowired EntityManager em; String queryStr = "select wsr.id as sampleid, s.id as slideid, tb.name as batchname, k.lot_number as kitlot, " + " 'STRING' as slidetype, tb.worklist_name as worklist, wsr.final_call as results, " + " wa.final_pattern_ids as patterns, 'edited/yesno' as edited, wsr.last_modified_by as user, wsr.last_modified_date as time " + " from slide s " + " left join table2 tb on s.test_batch_id = tb.id " + " left join table3 k on tb.kit_lot_id = k.id " + " left join table4 w on s.id = w.slide_id " + " left join tabl5 pw on pw.well_id = w.id " + " left join tabl6 cw on cw.well_id = w.id " + " left join tabl7 wsr on wsr.patient_well_sample_id = pw.id or wsr.control_sample_id = cw.id " + " left join (select * from *** (other subselect)) wa on wa.well_sample_id = wsr.**id or wa.well_sample_id = wsr.**id " + "where tb.state = 'STATENEEDED'"; public ArchiveDataListDTO getArchiveData(){ Query query = em.createNativeQuery(queryStr); ArchiveDataListDTO archiveDataListDTO = new ArchiveDataListDTO(); List<Object[]> resultL = (List<Object[]>)query.getResultList(); for( Object[] o : resultL){ archiveDataListDTO.addArchiveDataRow( new ArchiveDataDTO((String)o[0], String.valueOf(o[1]), (String) o[2], (String) o[3], (String) o[4], (String) o[5], (String) o[6], (String) o[7], (String) o[8], (String) o[9], (String) o[10])); } return archiveDataListDTO; }}
添加回答
举报
0/150
提交
取消