mybatis 中的where标签

mybatis中的where标签可以去除 开头的 and 或者 or 但是放在后面的不行

失败的:

<select id="countNotesByParam" parameterType="map"       resultType="int">
        select 
            count(*)
        from
            cn_note
        <where>
            <if test="userId !=null">
                cn_user_id= #{userId} and
            </if>
            <if test="statusId !=null">
                cn_note_status_id= #{statusId}
            </if>
        </where>
</select>    

and 放在后面不能自动去除

成功:

<select id="countNotesByParam" parameterType="map" resultType="int">
        select 
            count(*)
        from
            cn_note
        <where>
            <if test="userId !=null">
                cn_user_id= #{userId}
            </if>
            <if test="statusId !=null">
                and cn_note_status_id= #{statusId}
            </if>
        </where>
    </select>

 

如果不放在规定位置  也可以使用 trim标签

posted @ 2016-10-24 16:20  辰殇  阅读(1576)  评论(0编辑  收藏  举报