最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

在mybatis 中使用if else 進(jìn)行判斷的操作

 更新時(shí)間:2021年02月03日 16:39:27   作者:阿皓1024  
這篇文章主要介紹了在mybatis 中使用if else 進(jìn)行判斷的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧

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

<!-- 查詢物品的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標(biāo)簽以后,sql中不在使用where字段來限制條件

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

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

補(bǔ)充:mybaits中if 多個(gè)test 和 if else 分支支持

mybaits中if 多個(gè)test

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

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

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教。

相關(guān)文章

最新評(píng)論

沧源| 九江县| 边坝县| 英山县| 伊宁市| 瑞金市| 丹巴县| 大丰市| 诏安县| 怀集县| 三都| 砀山县| 钟祥市| 左贡县| 蓬安县| 凯里市| 盐津县| 井陉县| 左贡县| 呼和浩特市| 五原县| 巴塘县| 巩义市| 利川市| 含山县| 孝义市| 麻城市| 融水| 龙里县| 临武县| 滁州市| 黄龙县| 荔浦县| 锡林郭勒盟| 新闻| 同德县| 扬中市| 朔州市| 宜君县| 福清市| 黄龙县|