MyBatis根据用户id列表查询用户对象列表(MyBatis多对多查询)
接口编写:
// 根据uid查询对应的uname
List<User> selectListUserByListUid(List<Integer> uidList);
Mapper编写:
<select id="selectListUserByListUid" parameterType="java.util.List" resultType="com.chenzl.springboot.pojo.User">
select uid, uname, ucdate, role from user where uid in
<foreach collection="list" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</select>
利用foreach,判断uid是否在目标列表中,以实现根据列表筛选数据的效果。