Mybatis 參數是List>,建立 sql

很差意思,我只是記錄一下而已....sql

Mybatis 參數是List<Map<String, String>>,而後建立 sql 語句。bash

Mapperapp

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

Mapper.XMlide

<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>
複製代碼
相關文章
相關標籤/搜索