mybatis整合map查询过程中如果map的value的参数类型不一致时,new map集合的过程中不需要指定map的类型。在动态sql语句中指定具体查询的参数类型即可
public Result findScenicCommentLevel(@RequestParam(value = "province_ids",required = false) Integer province_ids,
@RequestParam(value = "city_ids",required = false) Integer city_ids,
@RequestParam(value = "ranks",required = false) String ranks,
@RequestParam(value = "scenic_ids",required = false) Integer scenic_ids) {
try {
Map querymap = new HashMap<>();
querymap.put("scenicId",scenic_ids);
querymap.put("province_ids",province_ids);
querymap.put("city_ids",city_ids);
querymap.put("ranks",ranks);
<select id="findNegativeCount" parameterType="java.util.Map" resultType="java.lang.Integer">
SELECT COUNT(a.`ranges`) FROM yq_comment a
<choose>
<when test="scenicId != null and scenicId != '' ">
INNER JOIN yq_scenic b ON a.scenic_id = b.`scenic_id`
where a.scenic_id = #{scenicId,jdbcType=INTEGER}
</when>
<otherwise>
where a.scenic_id in
(SELECT b.scenic_id FROM yq_scenic b where 1=1
<if test="province_ids != null and province_ids != ''">
and b.province_id = #{province_ids,jdbcType=INTEGER}
</if>
<if test="city_ids != null">
and b.city_id = #{city_ids,jdbcType=INTEGER}
</if>
<if test="rank !=null">
and b.rank = #{rank,jdbcType=VARCHAR}
</if>
)
</otherwise>
</choose>
GROUP BY a.`ranges` HAVING a.`ranges` = 3
</select>