foreach 注入在 mybatis 中不起作用

foreach injection is not working in mybatis

请帮我将标签注入@Delete 查询。

@Delete({"<script>","${__sql}","</script>"})
public int Delete(String __sql, List<Map<String, Object>> list);

__sql :

DELETE FROM MYTABLE WHERE KEY IN (<foreach collection='list' item='item' seperator=','> #{item.key} </foreach>)

我收到以下错误:

Caused by: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'item' not found. Available parameters are [__sql, list, param1, param2]

${} 中的标签未被评估。
您需要将 SQL provider@Lang 一起使用。

public interface YourMapper {
  @Lang(XMLLanguageDriver.class)
  @DeleteProvider(type = YourSqlProvider.class, method = "deleteSql")
  int Delete(String sql, List<Map<String, Object>> list);

  class YourSqlProvider {
    public String deleteSql(String sql) {
      return "<script>" + sql + "</script>";
    }
  }
}

这需要 MyBatis 3.5.1 或更高版本,IIRC。