如何在mybatis 中传多个参数
List getIdByRand(@Param(“question”) Question question,@Param(“sectionIdList”) List sectionIdList);
@param("") 映射参数到 xml 的 传入参数
xml:
parameterType=“map”
参数类型要写成map
如何在mybatis 中遍历 集合?
现在要遍历 List sectionIdList=new ArrayList<>(); 这个东西
<foreach collection=" sectionIdList " item="sectionId" separator="or" open="(" close=")">
sectionId=#{}
</foreach>
collection="" //要遍历的 参数 ,为 传进来的参数
item 在此情景中传进来的是string 的集合 item相当于 for循环中的控制变量
separator 分离来每个循环语句的 这里是OR
open,close 用来开始和关闭这个集合的。
examp:
sectionId=#{sectionId}循环展开:
(
sectionId=’’ or sectionId=’’ or sectionId=’’’
)