sql片段的定义

<!-- sql片段 id 表示唯一标示 这里不加where是因为 sql片段只对单表查询才抽取出来  这样的重用性更高 -->
    <sql id="query_user_where">
        <if test="userCustom!=null">
            <if test="userCustom.username != null and userCustom.username !=''">
                 user.username like('%${userCustom.username}%')
             </if>
        </if>
        <!-- and(id=3 or id=6 or id=7) -->
        <!-- collection包装对象的属性 item 集合属性的单个对象  open 拼接开始字符串 close 拼接结束字符串 separator 每次遍历中间的分割字符串-->
        <foreach collection="ids" item="id" open="and(" close=")" separator="or">
            id=#{id}
        </foreach>
    </sql>

 

posted on 2016-09-18 12:57  Lightt  阅读(678)  评论(0编辑  收藏  举报