第一种情况:在mapBean.xml文件里
controller层:
Map<String,Object> map = new HashMap<>();
map.put("intentionSalary",monthSalary);
service层
public List<Bean> listTalentScreen(Map map);
public List<Bean> listTalentScreen(Map map) {
return BeanDao.listTalentScreen(map);
}
dao层
public List<Bean> listTalentScreen(Map map);
BeanMapper.xml
<select id="listTalentScreen" parameterType="Map" resultMap="BeanResult">
select a.* from bean a where 1=1
<if test="intentionSalary!=null and intentionSalary!='' ">
and a.intention_salary in (#{intentionSalary})
</if>
</select>
第二种情况:使用foreach
只是在BeanMapper.xml文件不同,其他相同
<select id="listTalentScreen" parameterType="Map" resultMap="BeanResult">
select a.* from bean a where 1=1
<if test="intentionSalary!=null and intentionSalary!='' ">
and a.intention_salary in (#{intentionSalary})
<foreach collection="intentionSalary" index="index" item="intentionSalaryId" open="(" separator="," close=")">
#{intentionSalaryId}
</foreach>
</if>
</select>
粗略解释:
在控制层中 map.put(“intentionSalary”,monthSalary);
在*.xml中的collection选map中对应的key(即intentionSalary),item:就是intentionSalary的每一项,名字自取(比如intentionSalaryId),然后和下面的#{intentionSalaryId}对应