• 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标签

  • 相关阅读:
    第四周总结&实验报告二
    实验报告 一
    周总结
    期末总结
    第十二周作业
    第十一周作业
    第十周作业
    第九周作业
    第八周作业
    第五周课程总结&试验报告(三)
  • 原文地址:https://www.cnblogs.com/ZqNote/p/5993461.html
Copyright © 2020-2023  润新知