在使用 MyBatis 时如何在循环中使用 <bind>?

How can I use <bind> within a loop while using MyBatis?

我想构建一个 sql,如“(像 'a%' 的列或像 'b%' 或 ... 的列)”和 a、b 等。是集合中的元素。 所以我想出了 xml 这样的文件

<foreach item="item" collection="items" open="(" separator=" or " close=")">
<bind name="pattern" value="item + '%'" />
column like #{pattern}
</foreach

但是并没有像我想的那样成功。 sql 类似于“(像 'c%' 的列或像 'c%' 或 ... 的列)”,其中 c 是集合中的最后一个元素。 现在我使用 CONCAT 函数来完成这项工作。

column like CONCAT(#{pattern},'%')

还有其他好的方法来完成这项工作吗? 谢谢

这是一个已知的限制,即 <bind /> 不能在 <foreach /> 内使用,并且有一个开放的 issue.
目前使用 CONCAT 是一个很好的解决方法。