zoukankan      html  css  js  c++  java
  • 3.MyBatis常用

    1.数据库日期转格式

    DATE_FORMAT(measuring_time, '%Y-%m-%d') AS measuring_time,

    2.日期大于小于

    <if test="beginDate != null and beginDate != ''">
      AND DATE_FORMAT(measuring_time, '%Y-%m-%d') >= #{beginDate}
    </if>
    <if test="endDate != null and endDate != ''">
      AND DATE_FORMAT(measuring_time, '%Y-%m-%d') <= #{endDate}
    </if>


    转义字符串:

    <if test="startTime != null and startTime != ''">
       AND u.create_time >= #{startTime}
    </if>
    <if test="endTime != null and endTime != ''">
       AND u.create_time <= #{endTime}

    3.foreach写法

    <if test="healthStatuses != null">
      AND ha.health_status IN
      <foreach collection="healthStatuses" item="item" index="index" open="(" close=")" separator=",">
        #{item}
      </foreach>
    </if>

    4.模糊搜索

    <if test="teamName != null and teamName != '' ">
      AND team_name LIKE CONCAT('%', #{teamName} ,'%')
    </if>

    5.case when

    简单Case函数
    CASE sex
    WHEN '1' THEN ''
    WHEN '2' THEN ''
    ELSE '其他' END
     
    --Case搜索函数 
    CASE WHEN sex '1' THEN '' 
    WHEN sex '2' THEN '' 
    ELSE '其他' END  

    6.find_in_set

    <if test="chargeItemName != null and chargeItemName != ''">
        and find_in_set(charge_item_name,#{chargeItemName})
    </if>
    charge_item_name #{chargeItemName} 用逗号拼接的放在后面 字符串没有逗号的放在前面

      

    1 获取数据库中的有数据的日期

    SELECT

    DISTINCT DATE_FORMAT(create_time, '%Y-%m-%d')

    FROM

    t_health

    GROUP BY

    create_time

    ORDER BY

    create_time DESC

    LIMIT 50 

    不破不立,怕啥怼啥!
  • 相关阅读:
    Android一些问题
    内存泄漏(Memory Leak)
    内存溢出OOM
    Android面试题集合
    Handler之同步屏障机制(sync barrier)
    IdleHandler 原理浅析
    OkHttp原理
    RxJava操作符
    Android电量优化全解析
    Android内存优化大盘点
  • 原文地址:https://www.cnblogs.com/yslu/p/10836473.html
Copyright © 2011-2022 走看看