mybatis使用xml配置mapper

2020-04-17  本文已影响0人  风一样的存在

版本:mybatis-3.5.4.jar
当使用foreach标签时出现:


出现的问题

编写的xml配置如下:

<select id="selectPeriodByCompanyNames" resultMap="result">
        select id,
        company_name,
        `type`,
        publish_time,
        create_time,
        title,
        web_site,
        source from company_news_sum
        <where>
            publish_time <![CDATA[>=]]> #{startTime}
            and company_name in
            <foreach collection="list" item="company_name" index="index" open="(" close=")" separator=",">
                #{company_name}
            </foreach>
        </where>
</select>

解决办法:collection配置修改为参数名称

<select id="selectPeriodByCompanyNames" resultMap="result">
        select id,
        company_name,
        `type`,
        publish_time,
        create_time,
        title,
        web_site,
        source from company_news_sum
        <where>
            publish_time <![CDATA[>=]]> #{startTime}
            and company_name in
            <foreach collection="companyNames" item="company_name" index="index" open="(" close=")" separator=",">
                #{company_name}
            </foreach>
        </where>
</select>
上一篇 下一篇

猜你喜欢

热点阅读