springboot mybatis mapper.xml中sql in的入参是数组foreach写法总结
Mapper(本人没写dao层)接口类写法
public List<Custom> seachCustoms(@Param("fzr") String[] fzr);
1 <select id="seachCustoms" resultMap="customs" parameterType="list"> 2 select * from custom 3 where fzr in 4 <foreach collection="fzr" index="index" item="fzr" open="(" separator="," close=")" > 5 #{fzr} 6 </foreach> 7 8 </select>
注意 parameterType="list" 一定不能写成list、java.util.List、java.util.ArrayList、java.lang.String
否则会报错:错误信息是sql格式问题:就是入参是问号的错误