1. 使用IN实现多条件查询,传入的参数是String数组,如 issuePriority = ["ABC","BCD","EFG"]
2. 在MyBatis xml文件中,使用foreach,其中,需要使用$ 而不是#, {item}需要用单引号括起来,如'${item}'
<if test="issuePriority != null and issuePriority.length > 0 ">
and ISSUE_PRIORITY in <foreach collection="issuePriority" item="item" index="index" open="(" close=")" separator=",">
'${item}'
</foreach> </if>
<!-- 根據查詢條件,查詢需求信息 -->
<select id="getDailyWorkingIssueListWithArrayParameters" resultMap="DailyWorkingIssue">
SELECT *
FROM MES_KPI_ISSUE_T
WHERE 1=1
<if test="issueId != null and issueId != ''">
and ISSUE_ID = #{issueId}
</if>
<if test="issueSubject
MyBatis 利用foreach处理数组参数传入
最新推荐文章于 2023-07-04 16:41:20 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)