色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

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

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

瀏覽:5日期: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 數據庫
相關文章:
主站蜘蛛池模板: 色综合久久88色综合天天小说 | 欧美亚洲一区二区三区四 | 欧美视频精品一区二区三区 | 香港激情黄三级在线视频 | 国产精品欧美韩国日本久久 | 久久精品爱国产免费久久 | 久久亚洲精品永久网站 | 日本韩国三级在线 | 午夜影院美女 | 久久久欧美综合久久久久 | 免费在线亚洲 | 欧美无极品 | 亚洲欧美中文日韩二区一区 | 九九亚洲精品自拍 | 国内自拍网红在线综合 | 天堂一区二区三区精品 | 国产性生交xxxxx免费 | 成年人免费在线视频网站 | 美女视频黄视大全视频免费网址 | ppypp日本欧美一区二区 | 国产一久久香蕉国产线看观看 | 久草在线视频首页 | 男女福利 | 久久www视频| 最新国产区| 日韩在线视精品在亚洲 | 久久99精品久久久久久秒播 | 久久精品免费观看视频 | 特级做a爰片毛片免费看一区 | 亚洲精品久久久久久久777 | 日本不卡一区二区三区在线观看 | a毛片在线观看 | 欧美国产在线视频 | 日本成本人片 | 99久久国语露脸精品对白 | 欧美日韩精品一区二区三区视频 | 成年人在线网站 | 永久网站色视频在线观看免费 | 欧美午夜成年片在线观看 | 又黄又湿又爽吸乳视频 | 欧美怡红院在线 |