mybatis传入字符串分割成数组并且遍历

来源:互联网 发布:在线c语言编程器 编辑:程序博客网 时间:2024/05/20 14:42

      注意这里如果使用#会报错,所以使用$符号,如果不是数字类型,比如long,integer,还需加上单引号''。代码片段如下:

     <if test="pd.publishIds != null and pd.publishIds!= ''">
      and  p.publishId in
      <foreach collection="pd.publishIds" item="pId" index="index"
                open="(" close=")" separator=",">
                '${pId}'
            </foreach>
     </if>

     pId是类似于"a,b,c,d,e,f"的字符串,用逗号隔开。

原创粉丝点击