MYBATIS AND 在多条件组合下 后面的语句不能换行

mybatis 9个月前 will
718 0

MYBATIS AND 在多条件组合下 后面的语句不能换行

<select id="pageListCount" resultType="int">
        SELECT count(1)
        FROM
        customers c
        LEFT JOIN assets a ON c.guid = a.guid
        LEFT JOIN detection_daily_report ddr ON ddr.asset_id = a.id
        <trim prefix="WHERE" prefixOverrides="AND | OR">
            <!-- 这里是具体的语句  -->
        </trim>
</select>

这样是不可以的

<if test="triggerTimeStart != null and  triggerTimeEnd != null ">
    AND
    (ddr.report_create_time
    between
    #{triggerTimeStart}
    and
    #{triggerTimeEnd})
</if>

mybatis解析的sql结果

SELECT c.NAME AS `customer_name`, a.NAME AS `asset_name`, ddr.* FROM customers c LEFT JOIN
assets a ON c.guid = a.guid LEFT JOIN detection_daily_report ddr ON ddr.asset_id = a.id WHERE
AND (ddr.report_create_time between '2020-02-01 00:00:00' and '2020-02-29 23:59:59') ORDER
BY ddr.id DESC LIMIT 0, 10

这样是可以的

<if test="triggerTimeStart != null and  triggerTimeEnd != null ">
    AND (ddr.report_create_time
    between
    #{triggerTimeStart}
    and
    #{triggerTimeEnd})
</if>

mybatis解析的sql结果

SELECT c.NAME AS `customer_name`, a.NAME AS `asset_name`, ddr.* FROM customers c LEFT JOIN
assets a ON c.guid = a.guid LEFT JOIN detection_daily_report ddr ON ddr.asset_id = a.id WHERE
 (ddr.report_create_time between '2020-02-01 00:00:00' and '2020-02-29 23:59:59') ORDER
BY ddr.id DESC LIMIT 0, 10
版权声明:will 发表于 2020-02-23 18:58:06。
转载请注明:MYBATIS AND 在多条件组合下 后面的语句不能换行 | 敏利雅

暂无评论

您必须登录才能参与评论!
立即登录
暂无评论...