假设有如下一张表tab
id | col |
---|---|
1 | ["a", "b"] |
2 | ["a", "c"] |
3 | ["d", "e"] |
col type = varchar,数据是json array格式
需求:查询出col列包含a的记录
正确的sql
select * from tab where json_contains(col, json_array('a'))
对应MyBatis的标签则为
<!-- 需要配合for标签 -->
<select>
select * from tab where json_contains(col, json_array(
<for collection="list" item="item" separator=",">
#{item}
</for>
))
</select>