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

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

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

瀏覽:12日期: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 數據庫
相關文章:
主站蜘蛛池模板: 成人欧美午夜视频毛片 | 国内精品久久久久久久久蜜桃 | 亚洲高清视频在线播放 | 国产在线观看免费一级 | 欧美性色网 | 国产在线欧美精品 | 国产大臿蕉香蕉大视频女 | a级毛片在线播放 | 久久99精品久久久久久综合 | 欧美一级片观看 | 一级特黄色毛片免费看 | 美国一级毛片在线 | 亚洲gogo人体大胆西西安徽 | 一区二区三区四区在线视频 | 成人在线观看一区 | 午夜精品成人毛片 | 国产三级香港三韩国三级 | 久草在线视频免费资源观看 | 国产一级aaaaa毛片欧美 | 一级做a爰片性色毛片男 | 日本三级在线观看中文字 | 国产成人精品一区二三区 | 精品无码一区在线观看 | 国产伦理自拍 | 国产激情一区二区三区成人91 | 欧美成本人视频 | 久久精品一区二区三区四区 | 中国女人18xnxx视频 | 久草网址 | 成人毛片免费免费 | 欧美成人影院在线观看三级 | 免费一级毛片无毒不卡 | 九九视频精品在线 | 国产亚洲一区在线 | 久草视频免费在线看 | 狠狠88综合久久久久综合网 | 色综合久久91 | 亚洲爱爱爱 | 久草中文在线 | 91福利精品老师国产自产在线 | 亚洲国产成人在线视频 |