<select id="getEmployeesMapParams" resultType="Employees">
select *
from EMPLOYEES e
<where>
<if test="departmentId!=null and departmentId!=''">
e.DEPARTMENT_ID=#{departmentId}
</if>
<if test="employeeIdsArray!=null and employeeIdsArray.length!=0">
AND e.EMPLOYEE_ID in
<foreach collection="employeeIdsArray" item="employeeId"
index="index" open="(" close=")" separator=",">
#{employeeId}
</foreach>
</if>
</where>
</select>
employeeIdsArray.length - 改为 employeeIdsArray.size
本文介绍了一个使用MyBatis进行复杂条件查询的例子,包括根据部门ID和员工ID数组筛选记录的方法。通过<if>和<foreach>元素实现动态SQL,提高了查询的灵活性。
2909

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



