String sql = "SELECT gather.dwid,gather.dwname,recorditem.unit,record.id equiprecordid,record.equipname FROM eqm_equipgather_item gather LEFT JOIN eqm_equiprecord_item recorditem ON gather.equiprecorditemid =recorditem.id LEFT JOIN eqm_equiprecord record ON recorditem.equiprecordid =record.id WHERE record.equipmodelid = "
+ equipmodelid + " AND gather.dwname LIKE '%" + displayconfig.getDisplayname()
+ "%' AND gather.tenantid = " + tenantid + "";
Query query = em.createNativeQuery(sql);
query.unwrap(SQLQuery.class).addScalar("dwid", StandardBasicTypes.STRING)
.addScalar("dwname", StandardBasicTypes.STRING)
.addScalar("equiprecordid", StandardBasicTypes.LONG)
.addScalar("unit", StandardBasicTypes.STRING)
.addScalar("equipname", StandardBasicTypes.STRING)
.setResultTransformer(Transformers.aliasToBean(EquipgatheritemVo.class));
List<EquipgatheritemVo> gatherList = query.getResultList();
原生SQL组建查询
猜你喜欢
转载自blog.csdn.net/AlexKate/article/details/79743074
今日推荐
周排行