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

相关推荐

昨天 18:37
门头沟学院 Java
点赞 评论 收藏
分享
06-13 10:15
门头沟学院 Java
想去夏威夷的大西瓜在...:我也是27届,但是我现在研一下了啥项目都没有呀咋办,哎,简历不知道咋写
点赞 评论 收藏
分享
07-17 11:56
门头沟学院 Java
感谢东子的收留
码农索隆:好好好,优秀优秀
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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