方式一:传参ids是用逗号隔开
Mapper.java List<> selectByIds(@Param("ids") String ids); Mapper.xml <select id="selectByIds" parameterType="String" resultType="String"> select * from table a where a.id in <foreach item="item" index="index" collection="ids.split(',')" open="(" separator="," close=")"> #{item} </foreach> </select>
方式二:传参ids是用List<String> 集合
Mapper.java List<> selectByIds(@Param("ids") List<String> ids); Mapper.xml <select id="selectByIds" parameterType="list" resultMap="BaseResultMap"> select * from table a where a.id in <foreach item="item" index="index" collection="ids" open="(" separator="," close=")"> #{item} </foreach> </select>
标签:传参,Mapper,selectByIds,List,ids,Param,foreach,mybatis From: https://www.cnblogs.com/jsliao/p/17730341.html