mapper.xml
<mapper namespace="com.oracle.dao.one2manyDao"> <resultMap type="com.oracle.pojo.Order" id="orderResuleMap"> <id column="orderId" property="id"/> <result column="ordered_date" property="ordered_date"/> <result column="shipped_date" property="shipped_date"/> <result column="total" property="total"/> <collection property="orderlines" ofType="com.oracle.pojo.OrderLine" javaType="java.util.HashSet" column="order_id"> <id column="id" property="id"/> <result column="price" property="price"/> <result column="quantity" property="quantity"/> <result column="product" property="product"/> </collection> </resultMap> <select id="getOrderAndOrderLines" resultMap="orderResuleMap" parameterType="java.lang.Long"> select o.id as orderId,o.ordered_date,o.shipped_date,o.total, ol.id,ol.price,ol.quantity, ol.product from t_order o left join t_orderline ol on o.id=ol.order_id where o.id=#{id} </select> </mapper>
//实体类 public class OrderLine implements Serializable { private long id; private double price; private long quantity; private String product; private Order order; public class Order implements Serializable { private Long id; private Date ordered_date; private Date shipped_date; private Long total; private Set<OrderLine> orderlines = new HashSet<OrderLine>();