複数の時間タイプ (作成時間、監査時間など)、SQL での実装方法 (<choose> </choose> を使用)

<choose>
            <when test="rq.timeType != null and rq.timeType == 'createTime'">
                <if test="rq.startTime != '' and rq.startTime != null">
                    and s.createTime &gt;= #{rq.startTime}
                </if>
                <if test="rq.endTime != '' and rq.endTime != null">
                    and s.createTime &lt;= #{rq.endTime}
                </if>
            </when>
            <when test="rq.timeType != null and rq.timeType == 'salesTime'">
                <if test="rq.startTime != '' and rq.startTime != null">
                    and s.salesTime &gt;= #{rq.startTime}
                </if>
                <if test="rq.endTime != '' and rq.endTime != null">
                    and s.salesTime &lt;= #{rq.endTime}
                </if>
            </when>
            <when test="rq.timeType != null and rq.timeType == 'verifyTime'">
                <if test="rq.startTime != '' and rq.startTime != null">
                    and s.verifyTime &gt;= #{rq.startTime}
                </if>
                <if test="rq.endTime != '' and rq.endTime != null">
                    and s.verifyTime &lt;= #{rq.endTime}
                </if>
            </when>
            <otherwise>
                <if test="rq.startTime != '' and rq.startTime != null">
                    and s.salesTime &gt;= #{rq.startTime}
                </if>
                <if test="rq.endTime != '' and rq.endTime != null">
                    and s.salesTime &lt;= #{rq.endTime}
                </if>
            </otherwise>
        </choose>

おすすめ

転載: blog.csdn.net/linyiwwy/article/details/132166177