入参为List时,试了好几个方案比如封装为Map,List,但可能xml或者入参形式写的不对都没能成功,这里记录一个成功实现的写法。
1,mapper
使用@Param
List<PlanVO> selectPlanByOrgIds(@Param("orgIds") List<Long> orgIds, @Param("status") Integer status, @Param("pageNum") Integer pageNum, @Param("pageRows") Integer pageRows);
2,xml
<!--根据主机厂ID或ID集合查询内购方案并分页,根据不同用户权限调用,sql分页-->
<select id="selectPlanByOrgIds" parameterType="com.anji.allways.business.sales.vo.PlanVO"
resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from
csms_plan p
where 1=1 and p.brand_id in
<foreach item="item" index="index" collection="orgIds" open="(" separator="," close=")">
#{item}
</foreach>
<if test="status != null">
AND p.status = #{status}
</if>
and p.is_del = 0
limit #{pageNum}, #{pageRows}
</select>
需要说明的是:
1),collection = ? 答:与入参orgIds保持一致,不是List
2),item = ? #{?} 答:都是item