publicclassOrder{private Integer id;private String orderNo;private Date orderTime;private Date payTime;private String remark;/**订单详情*/private List<OrderDetail> orderDetailList;//省略get、set
1
2
3
4
5
6
7
8
9
10
11
12
13
1
2
3
4
5
6
7
8
9
10
11
12
13
OrderMapper.java
新增查询方法
List<Order>queryOrderList(Map map);
1
1
OrderMapper.xml
<resultMapid="BaseResultMap"type="com.chouxiaozi.mybatisdruid.entity.Order"><idcolumn="id"property="id"jdbcType="INTEGER"/><resultcolumn="order_no"property="orderNo"jdbcType="VARCHAR"/><resultcolumn="order_time"property="orderTime"jdbcType="TIMESTAMP"/><resultcolumn="pay_time"property="payTime"jdbcType="TIMESTAMP"/><resultcolumn="remark"property="remark"jdbcType="VARCHAR"/><collectionproperty="orderDetailList"ofType="com.chouxiaozi.mybatisdruid.entity.OrderDetail"><idcolumn="d_id"property="id"jdbcType="INTEGER"/><resultcolumn="d_order_no"property="orderNo"jdbcType="VARCHAR"/><resultcolumn="good_name"property="goodName"jdbcType="VARCHAR"/><resultcolumn="good_id"property="goodId"jdbcType="INTEGER"/><resultcolumn="good_count"property="goodCount"jdbcType="INTEGER"/></collection></resultMap><selectid="queryOrderList"resultMap="BaseResultMap">
SELECT
o.*, d.id as d_id,d.order_no as d_order_no,d.good_name,d.good_id,d.good_count
FROM
tbl_order o
LEFT JOIN tbl_order_detail d ON d.order_no = o.order_no
where 1=1
<iftest="orderNo != null and orderNo != ''">
and o.order_no = #{orderNo}
</if>
ORDER BY o.order_time desc
</select>
<!--主查询的resultMap--><resultMapid="BaseResultMap2"type="com.chouxiaozi.mybatisdruid.entity.Order"><idcolumn="id"property="id"jdbcType="INTEGER"/><resultcolumn="order_no"property="orderNo"jdbcType="VARCHAR"/><resultcolumn="order_time"property="orderTime"jdbcType="TIMESTAMP"/><resultcolumn="pay_time"property="payTime"jdbcType="TIMESTAMP"/><resultcolumn="remark"property="remark"jdbcType="VARCHAR"/><!--select子查询, column 传给子查询的参数--><collectionproperty="orderDetailList"ofType="com.chouxiaozi.mybatisdruid.entity.OrderDetail"select="queryDetail"column="order_no"></collection></resultMap><!--主查询的sql--><selectid="queryOrderList2"resultMap="BaseResultMap2">
SELECT
o.*
FROM
tbl_order o
where 1=1
<iftest="orderNo != null and orderNo != ''">
and o.order_no = #{orderNo}
</if>
ORDER BY o.order_time desc
</select><!--子查询的resultMap--><resultMapid="detailResuleMap"type="com.chouxiaozi.mybatisdruid.entity.OrderDetail"><idcolumn="id"property="id"jdbcType="INTEGER"/><resultcolumn="order_no"property="orderNo"jdbcType="VARCHAR"/><resultcolumn="good_name"property="goodName"jdbcType="VARCHAR"/><resultcolumn="good_id"property="goodId"jdbcType="INTEGER"/><resultcolumn="good_count"property="goodCount"jdbcType="INTEGER"/></resultMap><!--子查询的sql--><selectid="queryDetail"resultMap="detailResuleMap">
SELECT
*
FROM
`tbl_order_detail` where order_no = #{order_no}
</select>