欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

MyBatis中執(zhí)行相關(guān)SQL語句的方法

 更新時間:2023年08月16日 15:53:42   作者:weixin_46949892  
本文主要介紹了MyBatis中執(zhí)行相關(guān)SQL語句的方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧

1.between... and...

<if test="(reportStartDate != null and reportStartDate != '') || (reportEndDate != null and reportEndDate != '')">
    and report_date between #{reportStartDate} AND #{reportEndDate}
</if>

2.and   or

<if test="method != null">
    and ( Method like CONCAT('%', #{key ,jdbcType=VARCHAR}, '%')
    or EventCode like CONCAT('%', #{key ,jdbcType=VARCHAR}, '%')
    or EventName like CONCAT('%', #{key ,jdbcType=VARCHAR}, '%')
    )
</if>

3.like ---兩種寫法

<!--第一種寫法-->
<where>          
  <if test="reportRule != null and reportRule != ''">
      and report_rule like CONCAT('%',#{reportRule},'%')
  </if>           
</where>
<!--第二種寫法-->         
<where>
  <if test="custName != null and custName != ''">
      and cust_name like '%' #{custName} '%'
  </if>
  <if test="creater != null and creater != ''">
       and creater like '%' #{creater} '%'
  </if>
</where>

完整示例: 

<select id="findByQueryIds"  parameterType="string" resultType="java.lang.Integer">
    select id from t_monitor_suspicion_custom
    <where>
      <if test="(reportStartDate != null and reportStartDate != '') || (reportEndDate != null and reportEndDate != '')">
         and report_date between #{reportStartDate} AND #{reportEndDate}
      </if>
      <if test="reportRule != null and reportRule != ''">
         and report_rule like CONCAT('%',#{reportRule},'%')
      </if>
      <if test="custNo != null and custNo != ''">
         and cust_no like CONCAT('%',#{custNo},'%')
      </if>
      <if test="custName != null and custName != ''">
          and cust_name like CONCAT('%',#{custName},'%')
      </if>
      <if test="customType != null and customType != ''">
          and custom_type = #{customType}
      </if>
   </where>
   and (suspicion_status = #{value} or suspicion_status = #{value1})
</select>

 前端傳入cust_no為1019,后端實際查詢語句

[zl-aml-admin] DEBUG 2023-08-15 10:44:14.514 [http-nio-8081-exec-20] com.zlpay.modules.monitor.dao.SuspicionCustomDao.findByQueryIds [BaseJdbcLogger.java:137] - ==>  Preparing: select id from t_monitor_suspicion_custom WHERE cust_no like CONCAT('%',?,'%') and (suspicion_status = ? or suspicion_status = ?)
[zl-aml-admin] DEBUG 2023-08-15 10:44:14.516 [http-nio-8081-exec-20] com.zlpay.modules.monitor.dao.SuspicionCustomDao.findByQueryIds [BaseJdbcLogger.java:137] - ==> Parameters: 1019(String), 0(String), 3(String)
[zl-aml-admin] DEBUG 2023-08-15 10:44:14.519 [http-nio-8081-exec-20] com.zlpay.modules.monitor.dao.SuspicionCustomDao.findByQueryIds [BaseJdbcLogger.java:137] - <==      Total: 1

注意:由于一開始where語句只寫了 <if test="reportRule != null>沒有寫reportRule != ''" ,導致查詢結(jié)果出錯,所以我們?nèi)绻玫絼討B(tài)查詢的話,一定要搞清楚前端傳的是空值還是null值,如果不確定的話,就都判斷一下<if test="reportRule != null and reportRule != ''">

到此這篇關(guān)于MyBatis中執(zhí)行相關(guān)SQL語句的方法的文章就介紹到這了,更多相關(guān)MyBatis 執(zhí)行SQL語句內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • java內(nèi)存異常使用導致full?gc頻繁

    java內(nèi)存異常使用導致full?gc頻繁

    Full?GC是Java虛擬機中垃圾回收的一種方式,它會暫停應(yīng)用程序所有的線程并清理整個堆內(nèi)存。頻繁的Full?GC會導致應(yīng)用程序的性能下降,甚至出現(xiàn)長時間的停頓。Java內(nèi)存異常使用常常是Full?GC頻繁出現(xiàn)的原因之一,如使用大量的靜態(tài)變量、內(nèi)存泄漏等。
    2023-04-04
  • 基于@GetMapping注解攜帶參數(shù)的方式

    基于@GetMapping注解攜帶參數(shù)的方式

    這篇文章主要介紹了基于@GetMapping注解攜帶參數(shù)的方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-05-05
  • SpringCloud集成和使用OpenFeign的教程指南

    SpringCloud集成和使用OpenFeign的教程指南

    在微服務(wù)架構(gòu)中,服務(wù)間的通信是至關(guān)重要的,SpringCloud作為一個功能強大的微服務(wù)框架,為我們提供了多種服務(wù)間通信的方式,其中,OpenFeign是一個聲明式的Web服務(wù)客戶端,它使得編寫Web服務(wù)客戶端變得更加簡單,本文將詳細介紹如何在SpringCloud項目中集成和使用OpenFeign
    2024-10-10
  • spring 自動裝配和aop的使用

    spring 自動裝配和aop的使用

    這篇文章主要介紹了spring 自動裝配和aop的使用,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-07-07
  • Java帶default方法接口的應(yīng)用示例

    Java帶default方法接口的應(yīng)用示例

    這篇文章主要介紹了Java帶default方法接口的應(yīng)用,結(jié)合實例形式分析了java帶default方法接口定義、用法及相關(guān)操作注意事項,需要的朋友可以參考下
    2019-08-08
  • Windows系統(tǒng)安裝JDK小結(jié)

    Windows系統(tǒng)安裝JDK小結(jié)

    這篇文章主要給大家詳細介紹了Windows系統(tǒng)安裝JDK的方法和步奏,十分的細致,有需要的小伙伴可以參考下
    2016-03-03
  • Java超詳細整理講解各種排序

    Java超詳細整理講解各種排序

    這篇文章主要介紹了Java常用的排序算法及代碼實現(xiàn),在Java開發(fā)中,對排序的應(yīng)用需要熟練的掌握,這樣才能夠確保Java學習時候能夠有扎實的基礎(chǔ)能力。那Java有哪些排序算法呢?本文小編就來詳細說說Java常見的排序算法,需要的朋友可以參考一下
    2022-07-07
  • 用SpringMVC編寫一個HelloWorld的詳細過程

    用SpringMVC編寫一個HelloWorld的詳細過程

    SpringMVC是Spring的一個后續(xù)產(chǎn)品,是Spring的一個子項目<BR>SpringMVC?是?Spring?為表述層開發(fā)提供的一整套完備的解決方案,本文我們將用SpringMVC編寫一個HelloWorld,文中有詳細的編寫過程,需要的朋友可以參考下
    2023-08-08
  • IDEA在一個項目空間下管理多個項目的操作方法

    IDEA在一個項目空間下管理多個項目的操作方法

    這篇文章主要介紹了IDEA如何在一個項目空間下管理多個項目,本文通過圖文并茂的形式給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-04-04
  • Java數(shù)組操作經(jīng)典例題大總結(jié)

    Java數(shù)組操作經(jīng)典例題大總結(jié)

    數(shù)組是在內(nèi)存中存儲相同數(shù)據(jù)類型的連續(xù)的空間,聲明一個數(shù)組就是在內(nèi)存空間中劃出一串連續(xù)的空間,下面這篇文章主要給大家介紹了關(guān)于Java數(shù)組操作經(jīng)典例題的相關(guān)資料,需要的朋友可以參考下
    2022-03-03

最新評論