`

Mybatis 简单的判断语法

 
阅读更多
		   <!-- 多选
		   <choose>
			   <when test="title != null">
			     AND title like #{title}
			   </when>
			   <when test="author != null and author.name != null">
			     AND author_name like #{author.name}
			   </when>
			   <otherwise>
			     AND featured = 1
			   </otherwise>
		   </choose>
		   
		    -->
		    
		    <!-- 循环
		    <foreach item="item" index="index" collection="list"
			      open="(" separator="," close=")">
			        #{item}
			</foreach>
		    
		     -->
		     
		     <!-- trim 在这的作用是去掉所包含的前缀AND 或者OR 其他属性(suffixOverrides去掉后缀,加上前缀prefix,加上后缀suffix)
		     <trim prefix="WHERE" prefixOverrides="AND |OR ">
			    <if test="state != null">
			         state = #{state}
			    </if> 
			    <if test="title != null">
			        AND title like #{title}
			    </if>
			    <if test="author != null and author.name != null">
			        AND author_name like #{author.name}
			    </if>       
             </trim>
		      -->
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics