Mybatis 参数是List
2019-06-09  本文已影响0人  Kare

不好意思,我只是记录一下而已....

Mybatis 参数是List<Map<String, String>>,然后创建 sql 语句。

Mapper

List<Vod> getDetailsWithFilter(@Param(value = "list") List<Map<String, String>> filters, @Param(value="filterStr") String filterStr);

Mapper.XMl

<select id="getDetailsWithFilter" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from ff_vod
        <if test="list.size() > 0">
            where
        </if>

        <trim prefix="" suffixOverrides="and">
            <foreach collection="list" item="items" index="i">
                <foreach collection="items.entrySet()" item="value"
                    index="key">
                    <if test="key == 'area'">
                        vod_area=#{value,jdbcType=VARCHAR}
                        and
                    </if>
                    <if test="key == 'year'">
                        vod_year=#{value, jdbcType=VARCHAR}
                        and
                    </if>
                    <if test="key == 'letter'">
                        vod_letter=#{value,jdbcType=VARCHAR}
                        and
                    </if>
                    <if test="key == 'category'">
                        vod_cid=#{value,jdbcType=INTEGER}
                        and
                    </if>
                    <if test="key == 'language'">
                        vod_language=#{value,jdbcType=VARCHAR}
                        and
                    </if>
                </foreach>
            </foreach>
        </trim>
        <if test="filterStr != null">
            ORDER BY
            <choose>
                <when test="filterStr.equals('review')">
                    vod_gold
                </when>
                <when test="filterStr.equals('renqi')">
                    vod_up
                </when>
                <when test="filterStr.equals('time')">
                    vod_addtime
                </when>
            </choose>
            DESC
        </if>
    </select>

上一篇 下一篇

猜你喜欢

热点阅读