查询时间在某个范围内的mapper里语句

这篇博客主要讲解如何在Mybatis中使用Mapper来查询指定时间范围内的数据,通过创建一个包含开始和结束时间的入参实体,实现对数据库记录的筛选。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.mapper.xml,&gt,&lt
<select id="getAllByPage" resultType="com.chint.entity.ExceptionHandling">
    select a.*
    from exception_handling a
    <where>
        <if test="deliveryNoteNo != null and deliveryNoteNo != ''">
            and a.delivery_note_no like concat('%', #{deliveryNoteNo}, '%')
        </if>
        <if test="deliveryShipNo != null and deliveryShipNo != ''">
            and a.delivery_ship_no =#{deliveryShipNo}
        </if>
        <if test="startTime != null  and startTime != '' ">
            and DATE_FORMAT(alarm_time,'%Y-%m-%d') &gt;= DATE_FORMAT(#{startTime},'%Y-%m-%d')
        </if>
        <if test="endTime != null  and endTime != '' ">
            and DATE_FORMAT(alarm_time,'%Y-%m-%d') &lt;= DATE_FORMAT(#{endTime},'%Y-%m-%d')
        </if>
    </where>
    limit #{pageNum}
    , #{pageSize}

2.mapper

@Repository
public interface ExceptionHandlingMapper extends BaseMapper<ExceptionHandling> {

    List<ExceptionHandling> getAllByPage(ExceptionHandlingDto exceptionHandlingDto);}

3.入参实体

@Getter
@Setter
public class ExceptionHandlingDto implements Serializable {


    @ApiModelProperty("发货清单号")
    private String deliveryShipNo;

    @ApiModelProperty("交货单号")
    private String deliveryNoteNo;

    @ApiModelProperty("开始时间")
    private String startTime;

    @ApiModelProperty("结束时间")
    private String endTime;

    private int pageNum;

    private int pageSize;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值