mybatis-plus两表联查带分页带模糊查询所有订单信息

mapper.xml


    <resultMap id="orderMap" type="com.tenli.entity.Order">
        <id column="id" property="id"/>
        <result column="order_no" property="orderNo"/>
        <result column="course_id" property="courseId"/>
        <result column="course_title" property="courseTitle"/>
        <result column="course_cover" property="courseCover"/>
        <result column="teacher_name" property="teacherName"/>
        <result column="member_id" property="memberId"/>
        <result column="nickname" property="nickname"/>
        <result column="mobile" property="mobile"/>
        <result column="total_fee" property="totalFee"/>
        <result column="pay_type" property="payType"/>
        <result column="status" property="status"/>
        <result column="trade_type" property="tradeType"/>
        <result column="is_deleted" property="isDeleted"/>
        <result column="gmt_create" property="gmtCreate"/>
        <result column="gmt_modified" property="gmtModified"/>
        <!--        一对一关系-->
        <!--        column把第一次查询的某一个作为第二次查询的值
                    select把column列值交给select这个查询语句
        -->
        <association property="payLog" javaType="com.tenli.entity.PayLog">
            <id column="id" property="id"/>
            <result column="order_no" property="orderNo"/>
            <result column="pay_time" property="payTime"/>
            <result column="total_fee" property="totalFee"/>
            <result column="transaction_id" property="transactionId"/>
            <result column="trade_state" property="tradeState"/>
            <result column="pay_type" property="payType"/>
            <result column="attr" property="attr"/>
            <result column="is_deleted" property="isDeleted"/>
            <result column="gmt_create" property="gmtCreate"/>
            <result column="gmt_modified" property="gmtModified"/>
        </association>
    </resultMap>

    <!--    只要使用联表查询,必须使用resultMap   查询所有订单信息带分页-->
    <select id="findOrder" resultMap="orderMap">
        SELECT o.*,p.pay_time
        FROM t_order o left join t_pay_log p
        on o.order_no=p.order_no
        <where>
            1=1
            <if test="order.mobile !=null and order.mobile !=''">
                and o.mobile like concat('%',#{order.mobile},'%')
            </if>
            <if test="order.courseTitle !=null and order.courseTitle !=''">
                and o.course_title like concat('%',#{order.courseTitle},'%')
            </if>
            <if test="order.teacherName !=null and order.teacherName !=''">
                and o.teacher_name like concat('%',#{order.teacherName},'%')
            </if>
            <if test="order.startDate !=null and order.startDate !=''">
                and o.gmt_create >=#{order.startDate}
            </if>
            <if test="order.endDate !=null and order.endDate !=''">
                <![CDATA[and o.gmt_create <=#{order.endDate}]]>
            </if>
            <if test="order.status !=null and order.status !=''">
                and o.status =#{order.status}
            </if>
            <if test="order.orderNo !=null and order.orderNo !=''">
                and o.order_no =#{order.orderNo}
            </if>
            <if test="order.teacherName !=null and order.teacherName !=''">
                and o.teacher_name like concat('%',#{order.teacherName},'%')
            </if>
            <if test="order.payType !=null and order.payType !=''">
                and o.pay_type =#{order.payType}
            </if>

        </where>
            ORDER BY  p.pay_time DESC
    </select>

dao层

    Page<Order> findOrder(Page<Order> page1,@Param("order") OrderVo orderVo);

service 层接口

    CommonResult findOrder(Integer page, Integer limit, OrderVo orderVo);

service 层接口的实现类

/**
     * 查询所有订单信息带分页
     *
     * @param page
     * @param limit
     * @return
     */
    @Override
    public CommonResult findOrder(Integer page, Integer limit, OrderVo orderVo) {

        Page<Order> page1 = new Page<>(page, limit);

//        使用分页查询
        Page<Order> orderPage = orderDao.findOrder(page1, orderVo); //这个走的是mybatis的查询  orderVo 这就是装参数的

//         Page<Order> orderPage = orderDao.findOrder(page1, wrapper);   这个是走的mp 查询   wrapper mybatis可不认识

        if (orderPage != null) {
            return new CommonResult(2000, "查询订单信息成功", orderPage);
        }
        return new CommonResult(5000, "查询订单信息失败", null);
    }

controller层实现类

    /**
     * 查询所有订单信息带分页
     * @param page
     * @param limit
     * @return
     */
    @ApiOperation(value = "查询所有订单信息")
    @PostMapping("/findOrder/{page}/{limit}")
    public CommonResult findOrder(@PathVariable("page")Integer page, @PathVariable("limit") Integer limit,@RequestBody OrderVo orderVo) {
        System.out.println(orderVo);
        return orderService.findOrder(page,limit,orderVo);

    }

mapper.xml

 <resultMap id="orderMap" type="com.tenli.entity.Order">
        <id column="id" property="id"/>
        <result column="order_no" property="orderNo"/>
        <result column="course_id" property="courseId"/>
        <result column="course_title" property="courseTitle"/>
        <result column="course_cover" property="courseCover"/>
        <result column="teacher_name" property="teacherName"/>
        <result column="member_id" property="memberId"/>
        <result column="nickname" property="nickname"/>
        <result column="mobile" property="mobile"/>
        <result column="total_fee" property="totalFee"/>
        <result column="pay_type" property="payType"/>
        <result column="status" property="status"/>
        <result column="trade_type" property="tradeType"/>
        <result column="is_deleted" property="isDeleted"/>
        <result column="gmt_create" property="gmtCreate"/>
        <result column="gmt_modified" property="gmtModified"/>
        <!--        一对一关系-->
        <!--        column把第一次查询的某一个作为第二次查询的值
                    select把column列值交给select这个查询语句
        -->
        <association property="payLog" javaType="com.tenli.entity.PayLog">
            <id column="id" property="id"/>
            <result column="order_no" property="orderNo"/>
            <result column="pay_time" property="payTime"/>
            <result column="total_fee" property="totalFee"/>
            <result column="transaction_id" property="transactionId"/>
            <result column="trade_state" property="tradeState"/>
            <result column="pay_type" property="payType"/>
            <result column="attr" property="attr"/>
            <result column="is_deleted" property="isDeleted"/>
            <result column="gmt_create" property="gmtCreate"/>
            <result column="gmt_modified" property="gmtModified"/>
        </association>
    </resultMap>

    <!--    只要使用联表查询,必须使用resultMap   查询所有订单信息带分页-->
    <select id="findOrder" resultMap="orderMap">
        SELECT o.*,p.pay_time
        FROM t_order o join t_pay_log p
        where o.order_no=p.order_no

            <if test="ew.sqlSegment != null and ew.sqlSegment != '' and ew.nonEmptyOfWhere">
                and ${ew.sqlSegment}
            </if>


    </select>

dao层

导入包路径
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

@Param(Constants.WRAPPER)QueryWrapper wrapper加上这个就能进行模糊查询

    Page<Order> findOrder(Page<Order> page1,@Param(Constants.WRAPPER)QueryWrapper<Order> wrapper);

service 层接口

 CommonResult findOrder(Integer page, Integer limit, OrderVo orderVo);

service 层接口的实现类

 /**
     * 查询所有订单信息带分页
     *
     * @param page
     * @param limit
     * @return
     */
    @Override
    public CommonResult findOrder(Integer page, Integer limit, OrderVo orderVo) {

        QueryWrapper<Order> wrapper = new QueryWrapper<>();
        if (StringUtils.isNotEmpty(orderVo.getMobile())) {
            wrapper.like("o.mobile", orderVo.getMobile());
        }
        if (StringUtils.isNotEmpty(orderVo.getCourseTitle())) {
            wrapper.like("o.course_title", orderVo.getCourseTitle());
        }

        //    判断支付的时间
        if (StringUtils.isNotEmpty (orderVo.getEndDate())) {
            wrapper.between("p.pay_time", orderVo.getStartDate(),orderVo.getEndDate());
        }
        if (orderVo.getStatus() != null) {
            wrapper.eq("o.status", orderVo.getStatus());
        }
        if (StringUtils.isNotEmpty(orderVo.getOrderNo())) {
            wrapper.like("o.order_no", orderVo.getOrderNo());
        }
        if (StringUtils.isNotEmpty(orderVo.getTeacherName())) {
            wrapper.like("o.teacher_name", orderVo.getTeacherName());
        }
        if (orderVo.getPayType() != null) {
            wrapper.eq("o.pay_type", orderVo.getPayType());
        }
//        根据支付的时间倒序
        wrapper.orderByDesc("p.pay_time");
        Page<Order> page1 = new Page<>(page, limit);

         Page<Order> orderPage = orderDao.findOrder(page1, wrapper);
        if (orderPage != null) {
            return new CommonResult(2000, "查询订单信息成功", orderPage);
        }
        return new CommonResult(5000, "查询订单信息失败", null);
    }

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值