map传参在我们实际开发会经常用到,也是一种特别方便的传参方式。
话不多说上代码
service层:、
Map<String, Object> params = new HashMap<String, Object>();
List<Integer> passengerType = new ArrayList<>();
passengerType.add(1);
passengerType.add(2);
passengerType.add(3);
params.put("userId", 123456789L);
params.put("passengerType", passengerType);
List<UserCommonTravelers> list=userCommonTravelersMapper.selectUserComTraInfoByUserId(params);
Mapper文件:
//根据userid和passengerType查询
List<UserCommonTravelers> selectUserComTraInfoByUserId(Map<String, Object> params);
mapper.xml文件:
<select id="selectUserComTraInfoByUserId" resultMap="BaseResultMap" parameterType="java.util.Map">
select * from
user_common_travelers
where 1=1 and passenger_type in
<foreach item="item" index="index" collection="passengerType" open="(" separator="," close=")">
#{item}
</foreach>
<if test="userId != null" >
and user_id = #{userId}
</if>
</select>
注:collection=”passengerType”
好了,通过以上代码大家就知道了怎么用map传入带有list和对象(Long)进行动态查询了。
希望能帮到大家。
及时总结,不用加班。。。