Hibernate SQLQuery 原生SQL 查询及返回结果集处理-2
1.
返回List,
.setResultTransformer(
Transformers.ALIAS_TO_ENTITY_MAP);将结果转为Map,存放到list中,即list中为若干map对象;
获取可按此方法:
Map map = (Map) list.get(i);
System.out.println(map.get("table_colum_name"));
}
在jsp页面,可用S标签获取
<s:property value="table_colum_name" />
List list = new ArrayList();
Session session = null;
Transaction tx = null;
String strSql1 = "";
strSql1 = "select distinct testType.id,testType.mc from [" + damId + "_lb] as testType "
+ "inner join [" + damId + "_jcxm] as testObj on testObj.lbgl_id=testType.id "
+ "inner join [" + damId + "_cd] as testSite on testSite.jcxm_id=testObj.id "
+ "inner join [" + damId + "_sctj] as upLoadCond on upLoadCond.cd_id=testSite.id ";
try {
session = HibernateSessionFactory.getSession();
tx = session.beginTransaction();
Query query = session.createSQLQuery(strSql1).setResultTransformer(
Transformers.ALIAS_TO_ENTITY_MAP);
list = query.list();
tx.commit();
} catch (Exception e) {
e.printStackTrace();
tx.rollback();
throw e;
} finally {
session.close();
}
return list;
}
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。