侧边栏壁纸
博主头像
liuxy博主等级

细水长流,吃穿不愁

  • 累计撰写 37 篇文章
  • 累计创建 30 个标签
  • 累计收到 5 条评论

目 录CONTENT

文章目录

Mybatis Plus foreach 嵌套 判断

liuxy
2021-08-05 / 0 评论 / 3 点赞 / 630 阅读 / 227 字 / 正在检测是否收录...
温馨提示:
本文最后更新于 2022-08-22,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

话不多说直接上代码
gldjs 是List

<foreach collection="gldjs" item="gldj" open="(" close=")" index="index" separator="or">
    gldj = ${gldj}
    and exists(select 1
    from tb_fw_zfjc b
    where yxzt = '1'
    and a.syfw_id = b.syfw_id
    <choose>
        <when test="gldj == 1 ">
            and timestampdiff(day, jcrq, curdate()) > (30 - 3))
        </when>
        <when test="gldj == 2 ">
            and timestampdiff(day, jcrq, curdate()) > (90 - 7))
        </when>
        <when test="gldj == 3 ">
            and timestampdiff(day, jcrq, curdate()) > (365 - 15))
        </when>
    </choose>
</foreach>

拼接的结果

and
( gldj = 1
    and exists(select 1
    from tb_fw_zfjc b
    where yxzt = '1'
    and a.syfw_id = b.syfw_id and timestampdiff(day, jcrq, curdate())   > (30 - 3))
)
or 
    ( gldj = 3
    and exists(select 1
    from tb_fw_zfjc b
    where yxzt = '1'
    and a.syfw_id = b.syfw_id and timestampdiff(day, jcrq, curdate())   > (365 - 15))
)                 
or 
( gldj = 2
    and exists(select 1
    from tb_fw_zfjc b
    where yxzt = '1'
    and a.syfw_id = b.syfw_id  and timestampdiff(day, jcrq, curdate()) > (90 - 7))
)
3
广告 广告

评论区