EL表达式遍历集合显示异常处理

后台daoImpl
/**
 * 查找热门商品
 */
@Override
public List<ProdCommonProp> findHotShop() {
		String hql = "select * from (select t.* from       MEIJIA_MODEL_PROD_COMMON_PROP " +
				"t order by t.pcp_salenumber desc) t1 where rownum<=3";
		SessionFactory sessionFactory = this.getHibernateTemplate().getSessionFactory();
		Session session = sessionFactory.openSession();
		SQLQuery query = session.createSQLQuery(hql);
		return query.list();
	}
view层:
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>热门商品推荐</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
  <h1>${msg }</h1>
    <ul>
    	<c:forEach items="${prodCommonProps}" var="prod">
    	<li>商品名称:${prod.name} 销量:${prod.saleNum }</li>
    	</c:forEach>
    </ul>
    <br/>
  </body>
</html>
异常:
name被识别为int类型并报错
解决办法:
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>热门商品推荐</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
  <h1>${msg }</h1>
    <ul>
    	<c:forEach items="${prodCommonProps}" var="prod">
    	<li>商品名称:${prod[1]} 销量:${prod[11] }</li>
    	</c:forEach>
    </ul>
    <br/>
  </body>
</html>
原因:
          参考资料:http://blog.csdn.net/walkingmanc/article/details/7604485
        当对象有实体对应时.atrr没问题,但是如果没有关联实体,.atrr报错
           本例子dao层通过原生的SQL取出数据,所以整个过程没有与hibernate实体关联,无法直接去除属性

你可能感兴趣的:(EL表达式遍历集合显示异常处理)