在使用MyBatis操作list in时,可以通过以下技巧实现:
<select id="selectByIds" parameterType="java.util.List" resultType="com.example.User">
SELECT * FROM user WHERE id IN
<foreach item="id" collection="list" open="(" separator="," close=")">
#{id}
</foreach>
</select>
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("ids", listOfIds);
userMapper.selectByIds(paramMap);
<select id="selectByIds" parameterType="java.util.Map" resultType="com.example.User">
SELECT * FROM user WHERE id IN
<foreach item="id" collection="ids" open="(" separator="," close=")">
#{id}
</foreach>
</select>
通过以上技巧,可以方便地在MyBatis中操作list in,实现根据list中的多个id查询对应的数据。