亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術文章
文章詳情頁

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

瀏覽:18日期:2023-10-20 08:57:43

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

<!-- 查詢物品的id --><select parameterType='pd' resultType='java.lang.Integer'>SELECTi.itemsidFROM 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 表示并列

<if test='color!=null and personone!=null'>

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

mybaits中if 多個test

<select 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分支:

<select 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>

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

標簽: Mybatis 數據庫
相關文章:
主站蜘蛛池模板: 亚洲精品欧美在线 | 国产精品2022不卡在线观看 | 国产乱码精品一区二区三上 | 91丨国产 | 韩国成人在线视频 | 性欧美一级毛片欧美片 | 国产一级内谢a级高清毛片 国产一级毛片大陆 | 国产伦精品一区二区三区视频金莲 | 极品主播的慰在线播放 | 国产精品久久久久久免费 | 国内精品久久久久激情影院 | 免费黄色网址在线观看 | 一道精品一区二区三区 | 欧美不卡一区二区三区 | 精品哟哟哟国产在线不卡 | 亚洲欧美激情综合第一区 | 亚洲无线码一区二区三区在线观看 | 慈禧级淫片a级中文在线 | vr专区日韩精品中文字幕 | 九九免费精品视频在这里 | 国语对白清晰好大好白在线 | 欧美三级成版人版在线观看 | 亚洲w码| 中文国产成人精品久久水 | 免费观看国产精品视频 | 男女做www免费高清视频 | 国产精品美女免费视频观看 | 手机看片久久高清国产日韩 | 成人在线视频网站 | 亚洲一级毛片在线播放 | 一级做a爰片性色毛片视频图片 | 国产精品视频无圣光一区 | 日本一级特黄特色大片免费视频 | 亚洲福利在线观看 | 999热这里只有精品 999热精品这里在线观看 | 中国免费xxxx免费视频 | 国产一级一片免费播放 | 国产福利足控交在线观看 | 你懂得国产 | 亚洲制服在线观看 | 色婷婷久久综合中文久久一本` |