Mybatis进行多条件查询之where标签

where:

当where标签中有内容时,会自动生成where关键字,并且将内容前多余的and或or去掉

当where标签中没有内容时,此时where标签没有任何效果

注意:where标签不能将内容前的and去掉

1.接口类中的文件和上一篇文章一致 映射文件中的内容

<!--List<Emp> getEmpByCondition(Emp emp);-->
    <select id="getEmpByCondition" resultType="emp">
        select * from t_emp
        <where>
            <if test="empName!=null and empName !=''">
                emp_name=#{empName}
            </if>
            <if test="age!=null and age !=''">
                 age=#{age}
            </if>
            <if test="sex!=null and sex !=''">
                sex=#{sex}
            </if>
            <if test="email!=null and email !=''">
                email=#{email}
            </if>
        </where>
    </select>
全部评论

相关推荐

notbeentak...:孩子,说实话,选择很重要,可能你换一个方向会好很多,但是现在时间不太够了,除非准备春招
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务