mabatis使用in时,参数为逗号分隔的长串字符串如何处理

1.如果参数是英文数字混杂的

使用forEach循环分割

  <select id="selectNetSatutration" resultMap="BaseResultMap" parameterType="NetSatutrationVo" >
  
      SELECT 
      <include refid="Base_Column_List" />
      FROM NET_SATUTRATION t
      <where>
       <if test="orgNo != null and orgNo != '' " >
          exists (select 1 from (SELECT r.org_no 
                           FROM sy_pf_org_rela r 
                 WHERE org_rela_type = 'ADMINISTRATION' 
                          START WITH r.org_no = #{orgNo,jdbcType=VARCHAR}
                         CONNECT BY PRIOR r.org_no = r.org_parent_no) temp where temp.org_no=t.org_no)
        </if>
        <if test="statiDate != null and statiDate != '' " >
               and t.STATI_DATE = #{statiDate,jdbcType=VARCHAR}
        </if>
        <if test="netNo != null and netNo != '' " >
            and t.NET_NO in
            <foreach item="item" index="index" collection="netNo.split(',')" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
      </where>  
  </select>

 

 

2.如果是纯数字的

**还没测试过

  <select id="selectNetSatutration" resultMap="BaseResultMap" parameterType="NetSatutrationVo" >
  
      SELECT 
      <include refid="Base_Column_List" />
      FROM NET_SATUTRATION t
      <where>
       <if test="orgNo != null and orgNo != '' " >
          exists (select 1 from (SELECT r.org_no 
                           FROM sy_pf_org_rela r 
                 WHERE org_rela_type = 'ADMINISTRATION' 
                          START WITH r.org_no = #{orgNo,jdbcType=VARCHAR}
                         CONNECT BY PRIOR r.org_no = r.org_parent_no) temp where temp.org_no=t.org_no)
        </if>
        <if test="statiDate != null and statiDate != '' " >
               and t.STATI_DATE = #{statiDate,jdbcType=VARCHAR}
        </if>
        <if test="netNo != null and netNo != '' " >
            and t.NET_NO in (${netNo})
        </if>
      </where>  
  </select>

 

posted @ 2020-11-26 16:58  林被熊烟岛  阅读(250)  评论(0)    收藏  举报