foreach 语句为数组或对象集合中的每个元素重复一个嵌入语句组。foreach 语句用于循环访问集合以获取所需信息,但不应用于更改集合内容以避免产生不可预知的副作用。

如果是一个带数据的list对象

<select id="selectproductmstlist" resulttype="java.util.map" parametertype="map">
  select
     <foreach collection="fields" item="field" index="index" close="" separator=",">
      #{field.tablekoumokunames,jdbctype=varchar}
    </foreach>  
  from
    ${temp}.m_product
  left join ${temp}.m_type_cd on ${temp}.m_product.product_group_cd = ${temp}.m_type_cd.type_cd
  where
    ${temp}.m_product.anken_id = #{ankenid,jdbctype=varchar} and
    ${temp}.m_product.subsidiary_cd = #{subsidiarycd,jdbctype=varchar} and
    ${temp}.m_product.sub_anken_id = #{subankenid,jdbctype=varchar}
  order by
    ${temp}.m_product.subsidiary_cd asc,
    ${temp}.m_product.brand_cd asc,
    ${temp}.m_product.product_cd asc
</select>

遍历一个map对象:

map<string,object> xx=new hashmap<string, object>();
xx.put("22","abc");

parammap.put("maps",xx);
<foreach collection="maps" item="field" index="key" separator=",">
       ${field}={key}
    </foreach>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持www.887551.com。