一个hashmap页面显示问题(在线等)
有两个数据库,一个是订单Orders,一个是订单项表Orderitems
action里面数据
LinkedHashMap<List<Orders>,List<Orderitems>> map = new LinkedHashMap<List<Orders>,List<Orderitems>>();
List<Orders> l=odd.findOrder(u.getUsersId());
for(int i=0;i<l.size();i++){
List<Orderitems> l1=odd.findOrderitems(l.get(i).getOrdersId());
map.put(l, l1);
}
request.setAttribute("showorder", map);
return mapping.findForward("suss");
两个方法,肯定对,已测
public List findOrder(final Long userId) {
try{
result=(List)this.getHibernateTemplate().execute( new HibernateCallback(){
public Object doInHibernate(Session s) throws HibernateException,SQLException{
DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date dd = new Date();
java.sql.Date d = new java.sql.Date(dd.getTime());
Calendar c=Calendar.getInstance();
c.setTime(d);
int month=c.get(Calendar.MONTH)-1;
log.info("month------------"+month);
log.info("Calendar.MONTH----------------"+c.get(Calendar.MONTH));
log.info("YEAR--------------"+c.get(Calendar.YEAR));
c.set(c.get(Calendar.YEAR), month,c.get(Calendar.DAY_OF_MONTH));
String d0=sdf.format(c.getTime());
Date d1=java.sql.Date.valueOf(d0);
c.setTime(d);
int day=c.get(Calendar.DAY_OF_MONTH)+1;
log.info("day------------"+day);
log.info("Calendar.MONTH----------------"+c.get(Calendar.MONTH));
log.info("YEAR--------------"+c.get(Calendar.YEAR));
c.set(c.get(Calendar.YEAR),c.get(Calendar.MONTH),day);
String d2=sdf.format(c.getTime());
Date d3=java.sql.Date.valueOf(d2);
log.info("d1--------------------"+d1);
log.info("d---------------------"+d);
log.info("d2---------------------"+d2);
log.info("d3---------------------"+d3);
Query q = s
.createQuery("from Orders o where o.users.usersId=? and o.createtime >=? and o.createtime <=? order by o.createtime desc");
q.setLong(0, userId);
q.setDate(1, d1);
q.setDate(2, d3);
return q.list();
}
});
}catch (RuntimeException re) {
throw re;
}
return result;
}
public List findOrderitems(final Long ordersId) {
try{
result=(List)this.getHibernateTemplate().execute( new HibernateCallback(){
public Object doInHibernate(Session s) throws HibernateException,SQLException{
Query q = s
.createQuery("from Orderitems oi where oi.orders.ordersId=?");
q.setLong(0, ordersId);
return q.list();
}
});
}catch (RuntimeException re) {
throw re;
}
return result;
}
页面
<logic:notEmpty name="showorder">
<logic:iterate id="o" name="showorder" indexId="i">
<DIV class=Box-Center>
<TABLE>
<TBODY>
<TR>
<TD class=OrderInfo>
<LI>
<EM>订单时间:</EM>
<fmt:formatDate value="${o.key.createtime}" type="both" />
<LI>
<EM>订 单 号:</EM>#${o.key.ordersId }
<LI>
<EM>收 货 人:</EM>${o.key.address.username}
</LI>
</TD>
<TD class=OrderDetail>
<LI>
<EM>商品:</EM>
<logic:iterate id="oi" name="o"
property="value" indexId="i">
<LI class=Detail>
${oi.product.productname}
</LI>
</logic:iterate>
</TD>
<TD class=OrderOption>
<A href=""><IMG border=0 alt=查看订单
src="image/az-want-to-view-orders.gif"> </A>
</TD>
</TR>
</TBODY>
</TABLE>
</DIV>
</logic:iterate>
</logic:notEmpty>
问一下,为什么这种ER表达式无法显示,有什么错误吗?
还有LinkedHashMap有自己的key排序吗?因为我两个都是数组。。
或者各位大大能提供更好的方法,谢谢