美文网首页
Mybatis 参数是List

Mybatis 参数是List

作者: Kare | 来源:发表于2019-06-09 22:36 被阅读0次

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

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>

相关文章

网友评论

      本文标题:Mybatis 参数是List

      本文链接:https://www.haomeiwen.com/subject/ugeoxctx.html