- 使用<if>标签的时候,为了sql语法正确,需要在sql语句后加上where 1 = 1 才可以凭借if标签,这时候可以使用where标签,让sql语句更加简介,而这两种做法的效果是一样的。
<select id="findAll" resultMap="emp" parameterType="Emp2"> select * from tbl_employee <where> <if test="empId != null"> and id = #{empId} </if> <if test="empLastName != null"> and last_name = #{empLastName} </if> </where> </select>
Mybatis 细节(5)where标签
最新推荐文章于 2025-06-27 21:47:12 发布