String hql4 = “select * from student”";
List<Object[]> list = (List<Object[]>) this.hibernateTemplate
.execute(new HibernateCallback() {
@Override
public Object doInHibernate(Session session) throws HibernateException {
List<Object[]> list = (List<Object[]>)session.createSQLQuery(hql4).setFirstResult(start)
.setMaxResults(limit)
.list();
return list;
}
});
List<Map<String, Object>> res = new ArrayList<Map<String,Object>>();
for(Object[] o:list){
Map<String, Object> map= new HashMap<>();
try {
map.put("strategyName", o[0]);
map.put("kpiName", o[1]);
map.put("code", o[2]);
map.put("yesNoStandard", o[3]);
map.put("yesNoWatch", o[4]);
map.put("getName", o[5]);
map.put("alarmName", o[6]);
map.put("name", o[7]);
res.add(map);
} catch (Exception e) {
logger.error("object转map失败"+e);
}
}
hibernate使用原生sql
最新推荐文章于 2024-04-01 21:21:32 发布