原生SQL组建查询

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 gatherList = query.getResultList();

你可能感兴趣的:(java,原生SQL)