<select id="getPerson" resultType="com.lzj.bean.Employees">
select * from tbl_employees
<where>
<if test="id!=null">
id=#{id} and
</if>
<if test="lastName!=null and lastName!=''">
last_name like #{lastName} and
</if>
<if test="email!=null and email.trim()!=''">
email=#{email} and
</if>
<if test="gender==0 or gender==1">
gender=#{gender}
</if>
</where>
</select>
本文通过一个具体的MyBatis动态SQL示例,详细解释了如何使用if标签进行条件判断,实现根据参数动态构建SQL查询语句,提高SQL语句的灵活性和复用性。
3913

被折叠的 条评论
为什么被折叠?



