Configuration cfg = new Configuration().configure();
SessionFactory factory = cfg.buildSessionFactory();
Session session = factory.openSession();
Query query = session
.createQuery("select a.atdepot_id,i.indepot_drugName,i.indepot_generalName,i.indepot_packageStandard,a.atdepot_quantity,i.indepot_flag,i.indepot_drugStandard,i.indepot_lotNumber,i.indepot_period,i.indepot_unit,i.indepot_productionPlace,i.producer,i.supplier from IndepotDrug i, Atdepot a where i.indepot_drugId=a.indepot_drug");
List<Object> list = query.list();for (int i = 0; i < list.size(); i++) {
Object[] obj = (Object[]) list.get(i);
for (int j = 0; j < obj.length; j++) {
if (obj[j] instanceof IndepotDrug) {
IndepotDrug id = (IndepotDrug) obj[j];
System.out.print(id);
} else if (obj[j] instanceof Atdepot) {
Atdepot ad = (Atdepot) obj[j];
System.out.print(ad);
}
}
System.out.println();
}
这里打印不出对象。上面list.size()测试是有数据的。没有问题
请问这个list<object>怎么打印。怎么显示在jsp上面
我知道用request.setattribute可以传过去。就想知道怎么显示
因为打印不出来,不知道是什么结构
SessionFactory factory = cfg.buildSessionFactory();
Session session = factory.openSession();
Query query = session
.createQuery("select a.atdepot_id,i.indepot_drugName,i.indepot_generalName,i.indepot_packageStandard,a.atdepot_quantity,i.indepot_flag,i.indepot_drugStandard,i.indepot_lotNumber,i.indepot_period,i.indepot_unit,i.indepot_productionPlace,i.producer,i.supplier from IndepotDrug i, Atdepot a where i.indepot_drugId=a.indepot_drug");
List<Object> list = query.list();for (int i = 0; i < list.size(); i++) {
Object[] obj = (Object[]) list.get(i);
for (int j = 0; j < obj.length; j++) {
if (obj[j] instanceof IndepotDrug) {
IndepotDrug id = (IndepotDrug) obj[j];
System.out.print(id);
} else if (obj[j] instanceof Atdepot) {
Atdepot ad = (Atdepot) obj[j];
System.out.print(ad);
}
}
System.out.println();
}
这里打印不出对象。上面list.size()测试是有数据的。没有问题
请问这个list<object>怎么打印。怎么显示在jsp上面
我知道用request.setattribute可以传过去。就想知道怎么显示
因为打印不出来,不知道是什么结构
解决方案 »
- 提交表单问题,
- what is "Must Understand check failed for header"error?
- struts1.3 问题 Unhandled exception
- 高手们帮忙看看 这段程序为什么switch还有别的不执行啊
- 在使用ant的javac编译web service的stub文件时出现错误
- 请问:我要做一个基于J2EE的权限管理系统,应该怎么样下手?
- 有关velocity的问题
- 问两个Hibernate的问题,谢谢大家!
- java是怎样处理事务的?
- 紧急求助:关于weblogic上的webservice问题。。
- org.springframework.beans.factory.BeanCreationException
- 数据库与session会话 大家帮忙分析下
a.atdepot_id,i.indepot_drugName,i.indepot_generalName,i.indepot_packageStandard,a.atdepot_quantity,i.indepot_flag,i.indepot_drugStandard,i.indepot_lotNumber,i.indepot_period,i.indepot_unit,i.indepot_productionPlace,i.producer,i.supplier
这多麻烦啊,还不如直接查实体的好,
可以用query.scroll()的方法返回ScrollableResults,可以提取出相应字段的值,类似JDBC的ResultSet
可以查看API相关类如果是要对象的话用2楼的方法
return hibernateSession.createSQLQuery("select * from EmolumentLeafletInfo emo where emo.payment_Id="+id).addEntity(EmolumentLeafletInfo.class).list();
给你个例句自己套
这样你就可以通过list.get(0).get(0).来遍历了。
封装到一个对象是hibernate,或者说是MVC的普遍做法。但是这个对象并不对应数据库中的表所以无法进行持久化管理,可以直接封装到一个map里面,这样就不用多建一个类了。
到这里是对的。下面的都是错的。你们根本就没说重点。没人会就无满意结帖了
是一个数组。我上面写少了点
然后通过list.get(i).get(i)来遍历。不是没人说到重点。别人让你封装一个类处理也是对的,只是你自己不知道!!