Mybatis 参数是List<Map<String, String>>,创建 sql

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

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>
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容