1
如何在mybatis映射器中使用foreach
?我的意思是我应该发送什么参数?mybatis使用动态sql的foreach
比如我有这个select语句
<select id="findObjectsWithIds" resultMap="SimpleObjectResult">
SELECT * FROM testschema."XSimpleTable"
WHERE ID in
<foreach item="item" index="index" collection="list"
open="(" separator="," close=")">
#{item}
</foreach>
</select>
我有接口方法
List<SimpleObject> findObjectsWithIds(List<String> ids);
我有接口的实现
@Override
public List<SimpleObject> findObjectsWithIds(List<String> ids) {
SqlSession sqlSession = MyBatisSqlSessionFactory.openSession();
try {
SimpleMapper simpleMapper = sqlSession.getMapper(SimpleMapper.class);
return simpleMapper.findObjectsWithIds(ids);
} finally {
sqlSession.close();
}
}
而且当我试图运行 - 我有这个错误
如何正确使用foreach
?