java开发中,在mybatis.xml里的sql,取出集合list中String类型值,list存有post,day,work三个属性,要求在sql循环遍历中去掉其中的某个属性,比如去除item中的days字段
时间: 2023-05-21 07:02:49 浏览: 214
可以使用MyBatis的foreach标签来循环遍历list集合中的元素,然后使用substring函数去掉days字段。具体的SQL语句如下:
<foreach collection="list" item="item" separator="union all">
select post, substring(work, 1, instr(work, ',day')-1) as work
from table_name
where post = #{item.post} and day = #{item.day}
</foreach>
其中,list是传入的参数,item是循环遍历时的变量名,separator是分隔符,用于拼接多个SQL语句。substring函数用于截取work字段中days字段之前的部分,instr函数用于查找work字段中days字段的位置。
阅读全文
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![7z](https://img-home.csdnimg.cn/images/20241231044736.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)