mybatis 的动态sql

控制层就不多做解释了
@Override
public List<TO7xzApp> findRecommendDownByCategoryChilrenNameList(String categoryChildrenName, int size, List<String> idList) {
Map<String, Object> queryMap = Maps.newHashMap();
queryMap.put("categoryChildrenName", categoryChildrenName);
queryMap.put("remark3", "1");
queryMap.put("size", size);
queryMap.put("idList", idList);
return mapper.findRecommendDownByCategoryChilrenNameList(queryMap);
}

Mapper文件
List<TO7xzApp> findRecommendDownByCategoryChilrenNameList(Map<String, Object> queryMap);
这里直接传入一个map

再看xml文件
<select id="findHtmlStaticPageList" parameterType="hashmap" resultMap="BaseResultMap">
SELECT
CASE remark2 WHEN "soft" THEN "1" ELSE "2" END AS remark3,
<include refid="baseSql1" />
FROM
t_o7xz_app
<where>
<if test="categoryParentId != null and categoryParentId != ''">
and category_parent_id = #{categoryParentId}
</if>
<if test="id != null and id != ''">
and id LIKE CONCAT('%',#{id},'%')
</if>
<if test="appName != null and appName != ''">
and app_name LIKE CONCAT('%',#{appName},'%')
</if>
<if test="startTime != null and startTime != ''">
and create_time >= #{startTime}
</if>
<if test="endTime != null and endTime != ''">
and create_time <= #{endTime}
</if>
<if test="audit != null and audit != ''">
and audit=#{audit}
</if>
</where>
ORDER BY create_time desc
</select>

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

推荐阅读更多精彩内容