mybatis的foreach的使用

private MarketCategoryConversionRateMapper marketCategoryConversionRateMapper;

List<Integer> ids = new ArrayList<Integer>();
Map<String, Object> paramMap = new HashMap<String, Object>();
paramMap.put("allPeopleNum", allmemberNum);
paramMap.put("allConsumeNum", allsalesNum);
paramMap.put("idlist", ids);
this.marketCategoryConversionRateMapper.updateMarketConversionConversionRate(paramMap);



public interface MarketCategoryConversionRateMapper {

void updateMarketConversionConversionRate(Map<String, Object> paramMap);

}


<update id="updateMarketConversionConversionRate" parameterType="map"  >
        UPDATE  test SET ALL_PEOPLE_NUM=#{allPeopleNum},ALL_CONSUME_SUM=#{allConsumeNum}
         where ID IN 
        <foreach item="item" index="index" collection="idlist"   open="(" separator="," close=")">
               #{item}
                </foreach>
</update>



public void insertBatchSpecialCustomer(List<SpecialCustomerEntity> list ) ;

<insert id="insertBatchSpecialCustomer"  parameterType="java.util.List" >
            replace into SPECIAL_CUSTOMER
            (
                ID,
                SPECIAL_CUSTOMER_NAME,
                CUSTOMER_TYPE ,
                member_type,
                RULE , 
                HOBBY_RULE ,
                STATUS,
                SALES_REPORT_STATUS ,
                CREATE_TIME ,
                TRACK_REPORT_STATUS ,
                WIFI_REPORT_STATUS
            )  
            VALUES
            <foreach collection="list" item="item" index="index" separator="," >  
                        (
                          #{item.id},
                          #{item.specialCustomerName},
                          #{item.customerType},
                          #{item.memberType},
                          #{item.rule},
                          #{item.hobbyRule},
                          #{item.status},
                          #{item.salesReportStatus},
                          #{item.createTime},
                          #{item.trackReportStatus},
                          #{item.wifiReportStatus}
                        )  
            </foreach>
</insert>



public List<SpecialCustomerEntity> findSpecialCustomerInfoList(List<String> customerTypeList ) ;

<select id="findSpecialCustomerInfoList" parameterType="java.util.List" resultType="SpecialCustomerEntity">
        select  ID,SPECIAL_CUSTOMER_NAME as "specialCustomerName",CUSTOMER_TYPE as "customerType",
                member_type as "memberType",RULE , HOBBY_RULE as "hobbyRule",status ,
                SALES_REPORT_STATUS as "salesReportStatus" ,CREATE_TIME as  "createTime",
                TRACK_REPORT_STATUS as "trackReportStatus" ,
                WIFI_REPORT_STATUS as "wifiReportStatus" 
        from SPECIAL_CUSTOMER  where CUSTOMER_TYPE in 
         (
             <foreach collection="list" item="item" index="index" separator="," >  
                ${item}  
            </foreach>  
         )
</select>

 

posted @ 2015-06-27 18:39  沙漠里的小鱼  阅读(825)  评论(0编辑  收藏  举报