apache.ibatis.builder.BuilderException: Error evaluating expression ‘ids‘."/>
nested exception is org.apache.ibatis.builder.BuilderException: Error evaluating expression ‘ids‘.
# 前言
hello大家好,我是喜欢玩基金的秀总,今天在做基金工程时候遇到一个报错
## 异常
```
nested exception is org.apache.ibatis.builder.BuilderException: Error evaluating expression 'ids'.
```
出现此异常,一般是动态sql的问题,根据后面的提示信息,找到对应的sql,检查动态sql语法。
## 报错的sql
```
update ${tableName}
set is_deleted = ${isDelete}
where id in
<foreach collection="ids" item="item" separator="," open="(" close=")">
#{item}
</foreach>
```
## 思考
有时候报错肯定是sql出问题了,而且发现是ids这里,那么肯定这里有问题,于是我再看看接口种写法
```
void updateDelByIds(@Param("ids") String ids, @Param("isDelete") int isDelete,
@Param("tableName") String tableName);
````
## 发现
看到这里应该看出了什么,前面foreach应该是针对List进行循环,那么这里而是String类型
## 结论
1、所以要么java中将其转成List,再传到sql中
2、要么sql的foreach怎么写呢,.split(’,’)进行切割,注意是英文输入状态的单引号.
```
<foreach collection="ids.split(',')" item="item" separator="," open="(" close=")">
#{item}
</foreach>
```
小技巧
```
通过myBatis自带功能foreach,直接把逗号分隔的字符串传到mapper.xml即可,后台不用过多操作,Mapper.xml拼接部分sql如下:
```
更多推荐
nested exception is org.apache.ibatis.builder.BuilderException: Error evaluating
发布评论