Spring MVC Hibernate Eager Load JSTL c:foreach

时间:2015-10-07 18:58:37

标签: hibernate spring-mvc jstl

我在显示列表订单时遇到重复行的问题,该列表订单列出了具有一对多关联的项目。订单将重复订单中的商品数量,而不是每个订单的一次。

这是我的代码...... 控制器映射

<div>
Delivery
<table class="orders">
    <tr>
        <td>Order #</td>
        <td>Name</td>
        <td>Phone Number</td>
        <td>Street</td>
        <td>Items</td>
        <td>Total</td>
    </tr>

    <c:forEach var="deliveryKitchen" items="${deliveryKitchen}">
        <tr>
            <td><c:out value="${deliveryKitchen.idorders}"></c:out></td>
            <td><c:out value="${deliveryKitchen.users.name}"></c:out></td>
            <td><c:out value="${deliveryKitchen.users.phoneNo}"></c:out></td>
            <td><c:out value="${deliveryKitchen.addresses.street1}"></c:out>

    <td>
    <c:forEach var="insideItems" items="${deliveryKitchen.orderitem}">

            <c:out value="${insideItems.items.name}"></c:out>

    </c:forEach>    
...


 what the page shows 
Delivery
Order # Name    Phone Number    Street  Items   Total
57  Panikos 9172955593  214-04 33rd ave Healthy Wrap Meatlover's Omlette           18.4 Out for Delivery    Edit
57  Panikos 9172955593  214-04 33rd ave Healthy Wrap Meatlover's Omlette    18.4    Out for Delivery    Edit
59  Jerry   7894578978  2145 fulton Belgian Style Waffle Chicken Salad Two    Eggs Tuna Salad Sandwich Chicken Noodle Baja Chicken Macaroni and Cheese (kids)  Western Omlette  53.4    Out for Delivery    Edit
59  Jerry   7894578978  2145 fulton Belgian Style Waffle Chicken Salad Two Eggs Tuna Salad Sandwich Chicken Noodle Baja Chicken Macaroni and Cheese (kids) Western Omlette  53.4    Out for Delivery    Edit
59  Jerry   7894578978  2145 fulton Belgian Style Waffle Chicken Salad Two Eggs Tuna Salad Sandwich Chicken Noodle Baja Chicken Macaroni and Cheese (kids) Western Omlette  53.4    Out for Delivery    Edit
59  Jerry   7894578978  2145 fulton Belgian Style Waffle Chicken Salad Two Eggs Tuna Salad Sandwich Chicken Noodle Baja Chicken Macaroni and Cheese (kids) Western Omlette  53.4    Out for Delivery    Edit
59  Jerry   7894578978  2145 fulton Belgian Style Waffle Chicken Salad Two Eggs Tuna Salad Sandwich Chicken Noodle Baja Chicken Macaroni and Cheese (kids) Western Omlette  53.4    Out for Delivery    Edit
59  Jerry   7894578978  2145 fulton Belgian Style Waffle Chicken Salad Two Eggs Tuna Salad Sandwich Chicken Noodle Baja Chicken Macaroni and Cheese (kids) Western Omlette  53.4    Out for Delivery    Edit
59  Jerry   7894578978  2145 fulton Belgian Style Waffle Chicken Salad Two Eggs Tuna Salad Sandwich Chicken Noodle Baja Chicken Macaroni and Cheese (kids) Western Omlette  53.4    Out for Delivery    Edit
59  Jerry   7894578978  2145 fulton Belgian Style Waffle Chicken Salad Two Eggs Tuna Salad Sandwich Chicken Noodle Baja Chicken Macaroni and Cheese (kids) Western Omlette  53.4    Out for Delivery    Edit

    // GET ORDERS BY STATUS
@SuppressWarnings("unchecked")
public List<Orders> getDeliveryKitchen() {
    Criteria crit = session().createCriteria(Orders.class);
    crit.createCriteria("status", "c");
    crit.add(Restrictions.eq("c.idstatus", 2));

    return crit.list();
}

.jsp

的一部分
{{1}}

1 个答案:

答案 0 :(得分:0)

尝试一下:

Criteria crit = session().createCriteria(Orders.class);
crit.createCriteria("status", "c");
crit.add(Restrictions.eq("c.idstatus", 2));
crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);