首先查看,数据库字段:
书写映射实体类对象VO:
@Data
public class OrderListVO implements Serializable {private Integer orderId;private String memberName;private String orderNumber;private BigDecimal orderPrice;private String logisticsNo;private String status;private LocalDateTime createTime;private LocalDateTime sendTime;
}
编写sql语句:
<select id="select" resultMap="orderPageList" parameterType="net.wanho.qz112.shop.order.dto.OrderListDTO">SELECT sod.order_id orderId, sm.username memberName,sod.order_number orderNumber,sod.order_price orderPrice,sod.is_send isSend,sod.logistics_no logisticsNo,sod.`status`,sod.create_time createTime,sod.send_time sendTimeFROM `sp_order` sodLEFT JOIN sp_member sm on sod.member_id = sm.idwhere sm.is_deleted = 0<if test="orderNumber!=null and orderNumber!=''">and order_number=#{orderNumber}</if><if test="username!=null and username!=''">and username=#{memberName}</if><if test="isSend!=null and isSend!=''">and is_send=#{isSend}</if><if test="status!=null">and status=#{status}</if><if test="beginTime!=null and endTime!=null">and create_time BETWEEN #{beginTime} AND #{endTime}</if></select>
编写映射Map:
<resultMap id="orderPageList" type="net.wanho.qz112.shop.order.vo.OrderListVO"><id column="orderId" property="orderId"/><result column="memberName" property="memberName"/><result column="orderNumber" property="orderNumber"/><result column="orderPrice" property="orderPrice"/><result column="isSend" property="isSend"/><result column="logisticsNo" property="logisticsNo"/><result column="status" property="status"/><result column="createTime" property="createTime"/><result column="sendTime" property="sendTime"/></resultMap>
mapper接口:
List<OrderListVO> select(OrderListDTO orderListDTO);
service:接口
Map<String, Object> findOrder(Integer pageNum, Integer pageSize, OrderListDTO order);
映射完成后,通过serviceImpl调用:
public Map<String, Object> findOrder(Integer pageNum, Integer pageSize, OrderListDTO order) {PageHelper.startPage(pageNum,pageSize);List<OrderListVO> list = orderMapper.select(order);Map<String,Object> map = new HashMap<>(3);PageInfo pageInfo = new PageInfo(list);map.put("total",pageInfo.getTotal());map.put("pageNum", pageInfo.getPageNum());map.put("orders", pageInfo.getList());return map;}
controller:
@Resourceprivate OrderService orderService;@GetMapping("/orders")public AjaxResult findPage(Integer pageNum, Integer pageSize, OrderListDTO order) {Map<String,Object> map = orderService.findOrder(pageNum,pageSize,order);return AjaxResult.success("获取订单列表成功!",map);}
实现图片:
此处有弊端,请移步下一篇……
使用LocalDateTime不能映射空值?