例如查询是否过期,需要格式化时间,并且与当前时间比较;也可以前端传递自定义时间

使用

<![CDATA[]]>和'%Y-%m-%d'
   SELECT *
      
        from user c 
      
        <where>
            and c.deleted = 0
            <!-- 状态 -->
            <if test="status != null and status!=''">
                <choose>
                    <!-- 状态-未生效 -->
                    <when test="status == 'NOT_ACTIVE'">
                        <![CDATA[and  date_format( c.effect_date,'%Y-%m-%d') > date_format( now(),'%Y-%m-%d') ]]>
                    </when>

                    <!-- 状态-已生效 -->
                    <when test="status == 'ACTIVE'">
                        <![CDATA[and  date_format( c.effect_date,'%Y-%m-%d') <= date_format( now(),'%Y-%m-%d') ]]>
                        <![CDATA[and  date_format( c.failure_date,'%Y-%m-%d') >= date_format( now(),'%Y-%m-%d') ]]>
                    </when>
                    <!-- 状态-已过期 -->
                    <when test="status == 'EXPIRED'">
                        <![CDATA[and date_format( c.failure_date,'%Y-%m-%d') < date_format( now(),'%Y-%m-%d') ]]>
                    </when>
                </choose>
            </if>
  order by create_time desc

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐