第二篇:个人方法:
1.
返回List,
.setResultTransformer(
Transformers.ALIAS_TO_ENTITY_MAP);将结果转为Map,存放到list中,即list中为若干map对象;
获取可按此方法:
for
(
int
i
=
0
; i
<
list.size(); i
++
) {
Map map = (Map) list.get(i);
System.out.println(map.get( "table_colum_name " ));
}
Map map = (Map) list.get(i);
System.out.println(map.get( "table_colum_name " ));
}
在jsp页面,可用S标签获取
<s:property value="table_colum_name" />
public
List getDamTestType(Integer damId)
throws
Exception {
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;
}
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;
}