nested exception is org.apache.ibatis.builder.BuilderException: Error evaluating expression ‘ids‘.

编程入门 行业动态 更新时间:2024-10-27 15:24:18

nested exception is org.<a href=https://www.elefans.com/category/jswz/34/1769910.html style=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

本文发布于:2024-03-07 15:51:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1718245.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:apache   ibatis   org   nested   exception

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!