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>
全部评论

相关推荐

27届毕业,最近想找一段大厂实习,感觉简历有些问题,好多都不给面,求大佬们指点,最近好焦虑
后端劝退第91人:我从后端的角度分析一下你的第一个项目,我感觉亮点不是很突出。因为我是因为组内有需求,临时上手学react干活。我用到的技术基本就cover你那个智慧园区管理平台的很多亮点了。那作为比较专业的前端,你上述的内容是不是有点单薄呢。感觉还得包装
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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