我已经使用了这个列表,现在我怎样才能为每个循环获取每个元素?
public String execute(){
Query query=HibernateUtil.currentSession().createSQL("SELECT u.id,u.orderId,p.productName,u.key2,i.for_sponsor_id FROM useller_orders u join prod on p.productId=u.productId "
+ "join ir i on u.key2=i.id where p.productName like '%FEE%'"
+ " and u.createdDate > '" + createdDate + "' "
+ "and forced_matrix_sponsor_id is null "
+ "order by u.key2");
List<Object> list = query.list();
我想让U.ID在循环中打印
答案 0 :(得分:0)
'foreach'循环的语法:
for (Object o : list) {
}
如果您以某种方式知道列表中包含的特定元素类型,您也可以投射:
for (Object o : list) {
TheClass item = (TheClass)o;
// use the item
}
答案 1 :(得分:0)
根据Hibernate Documentation,返回的列表是对象数组的列表。因此,您需要将最后一行更改为
List<Object[]> list = query.list();
然后写
for (Object[] arr : list) {
System.out.println(arr[0]);
}