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 

    不破不立,怕啥怼啥!
  • 相关阅读:
    Java学习之路(一)——JDK的下载与安装
    无法将“add-migration”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。解决方案
    VS2019只能提示选中首选项的快捷键切换
    Visual Studio空格变成点的快捷键切换
    Visual Studio 2019 打开即时窗口
    完全卸载node.js
    安装node.js和vue
    在后台启动Redis
    mysql的数据库优化方案
    hadoop
  • 原文地址:https://www.cnblogs.com/yslu/p/10836473.html
Copyright © 2011-2022 走看看