myBatis 查询时注意and拼接条件

<!-- 加个条件 -->
    

<sql id="queryjiachaAllPageId">
        <where>
            <if test="danweimc !=null and danweimc !=''">
                and jcb.danweimc like '%${danweimc}%'
            </if>
             <if test="ge_jianchaks !=null and ge_jianchaks !=''">
               and DATE_FORMAT(jcb.jianchaks, '%Y-%m-%d') >= #{ge_jianchaks}
            </if>
            <if test="le_jianchaks != null and le_jianchaks != ''">
               and DATE_FORMAT(jcb.jianchaks, '%Y-%m-%d') &lt;= #{le_jianchaks}
            </if>
           
            <if test="jiancharxm !=null and jiancharxm !=''">
               and jcb.jiancharxm like '%${jiancharxm}%'
            </if>
            <if test="zhuangtai !=null and zhuangtai !=''">
               and yhb.zhuangtai = ${zhuangtai}
            </if>
            <if test="danweilb !=null and danweilb !=''">
               and yhb.yinhuanmc like '${danweilb}%'
            </if>
            <if test="jiedao != null and jiedao !='' and jiedao !='110105000000'">
              and jcb.jiedao=#{jiedao}
            </if>
            <if test="danweimcs != null and danweimcs !=''">
              and jcb.danweimc = #{danweimcs}
            </if>
        </where>
    </sql>


    ========================
    例如上诉问题  要么都加and ,要么都不加 ,一定要注意,如果有加and 和没有加and的 查询会报错

博主原创,转载请注明出处: https://blog.csdn.net/qq_36698956

版权声明:博客对我来说是记忆的笔记和知识的分享~此博文为博主原创转载请注明出处即可~ 

猜你喜欢

转载自blog.csdn.net/qq_36698956/article/details/81234076