一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|JavaScript|易語言|

服務器之家 - 編程語言 - Java教程 - 在mybatis 中使用if else 進行判斷的操作

在mybatis 中使用if else 進行判斷的操作

2021-08-03 10:55阿皓1024 Java教程

這篇文章主要介紹了在mybatis 中使用if else 進行判斷的操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

我就廢話不多說了,大家還是直接看代碼吧~

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<!-- 查詢物品的id -->
    <select id="checkItemsId" parameterType="pd" resultType="java.lang.Integer">
        SELECT
            i.itemsid
        FROM pq_goods_items i
        
        <where>
   <!--方式一使用choose的方式查詢-->
   <!-- <choose>
    <when test="parentId !=0 ">parentTypeId=#{parentId}</when>
    <when test="parentId==0">parentTypeId is null</when>
   </choose> -->
   <!--方式二使用if的方式查詢-->
   <if test="color!=null">
     i.personone=#{personone}
            AND i.persontwo=#{persontwo}
   AND i.color=#{color}
   </if>
   <if test="color==null">
     i.personone=#{personone}
            AND i.persontwo=#{persontwo}
   AND i.color is null
   </if>
  </where>
    </select>

需要注意的是 使用了where標簽以后,sql中不在使用where字段來限制條件

如果判斷條件有多個 中間用 and 表示并列

?
1
<if test="color!=null and personone!=null">

補充:mybaits中if 多個test 和 if else 分支支持

mybaits中if 多個test

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<select id="selectByDynamicallyWithPage" parameterType="map" resultMap="BaseResultMap">
 select
 <include refid="Base_Column_List" />
 from gene_polymorphism
 <where>
  diag_id = #{conds.diagId,jdbcType=INTEGER}
  <if test="conds.chromesome!=null and conds.chromesome!=''">
  and chromesome = #{conds.chromesome,jdbcType=VARCHAR}
  </if>
  <if test="conds.startPos!=null">
  and start_pos &gt;= #{conds.startPos,jdbcType=BIGINT}
  </if>
 </where>
</select>

if else分支:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<select id="selectByDynamicallyWithPage" parameterType="map" resultMap="BaseResultMap">
 select
 <include refid="Base_Column_List" />
 from gene_polymorphism
 <where>
  diag_id = #{conds.diagId,jdbcType=INTEGER}
  <if test="conds.chromesome!=null">
  and chromesome = #{conds.chromesome,jdbcType=VARCHAR}
  </if>
  <if test="conds.startPos!=null">
  and start_pos &gt;= #{conds.startPos,jdbcType=BIGINT}
  </if>
  <if test="conds.endPos!=null">
  and end_pos &lt;= #{conds.endPos,jdbcType=BIGINT}
  </if>
  <if test="conds.geneTypes!=null">
  <!--and gene_type in-->
  <!--<foreach collection="conds.geneTypes" open="(" close=")" item="item" separator="," >-->
   <!--#{item,jdbcType=VARCHAR}-->
  <!--</foreach>-->
  and (
  <foreach collection="conds.geneTypes" item="item" separator="or">
   gene_type like CONCAT('%',CONCAT(#{item,jdbcType=VARCHAR}, '%'))
  </foreach>
  )
  </if>
  <if test="conds.geneChange!=null">
  and gene_change like CONCAT('%',CONCAT(#{conds.geneChange,jdbcType=VARCHAR}, '%'))
  </if>
 </where>
 order by
 <trim suffixOverrides=",">
  <choose>
  <when test="conds.chromesomeSort!=null and conds.chromesomeSort=='asc'">
   chromesome asc ,
  </when>
  <when test="conds.chromesomeSort!=null and conds.chromesomeSort=='desc'">
   chromesome desc ,
  </when>
  </choose>
  <choose>
  <when test="conds.startPosSort!=null and conds.startPosSort=='asc'">
   start_pos asc ,
  </when>
  <when test="conds.startPosSort!=null and conds.startPosSort=='desc'">
   start_pos desc ,
  </when>
  <otherwise>
   id desc
  </otherwise>
  </choose>
 </trim>
  limit #{startRow,jdbcType=INTEGER} ,#{pageSize,jdbcType=INTEGER}
 <!-- order by id desc limit #{startRow,jdbcType=INTEGER} ,#{pageSize,jdbcType=INTEGER} -->
 </select>

以上為個人經驗,希望能給大家一個參考,也希望大家多多支持服務器之家。如有錯誤或未考慮完全的地方,望不吝賜教。

原文鏈接:https://blog.csdn.net/pqsas_com/article/details/75337608

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 大学第一次基本都没了 | 国产做a爰片久久毛片 | 东北老妇露脸xxxxx | 欧美一区不卡二区不卡三区 | 免费日本在线 | 四虎影视在线观看永久地址 | 二区三区在线观看 | 黑人video粗暴日本 | 日本精品一二三区 | 丰满大乳欲妇三级k8 | 国产成人精品实拍在线 | 二区三区不卡不卡视频 | 免费观看视频在线播放 | www.色女人.com| 青青草在观免费 | 欧洲肥女大肥臀 | 15一16japanese破 | 91美女在线视频 | 男人在线影院 | 亚欧成人中文字幕一区 | 紧身牛仔裤美女被啪啪久久网 | 国产东北三老头伦一肥婆 | 古代双性美人被老糟蹋 | 性导航h| 亚洲看片lutube在线入口 | 精品无码人妻一区二区免费AV | 亚洲视频在线观看免费 | 毛片亚洲毛片亚洲毛片 | 丝袜老师好湿好紧我要进去了 | 欧美在线视频 一区二区 | 1919gogo女厕盗摄 | 视频一区二区国产 | 91视频免费观看网站 | 欧美 国产 日韩 第一页 | 国产一级黄色录像 | gay勾搭直男com | a片毛片在线免费看 | 欧美日本一道高清免费3区 欧美人做人爱a全程免费 | 日韩欧美天堂 | 龟甲情感超市全文阅读 小说 | 午夜福利合集1000在线 |