1. 程式人生 > >mybatis如何傳入一個list參數

mybatis如何傳入一個list參數

.class this day ava _id param java clas birt

<!-- 7.2 foreach(循環List<String>參數) - 作為where中in的條件 -->
<select id="getStudentListByClassIds_foreach_list" resultMap="resultMap_studentEntity">
SELECT ST.STUDENT_ID,
ST.STUDENT_NAME,
ST.STUDENT_SEX,
ST.STUDENT_BIRTHDAY,
ST.STUDENT_PHOTO,
ST.CLASS_ID,
ST.PLACE_ID
FROM STUDENT_TBL ST
WHERE ST.CLASS_ID IN
<foreach collection="list" item="classIdList" open="(" separator="," close=")">
#{classIdList}
</foreach>
</select>

測試代碼,查詢學生中,在20000001、20000002這兩個班級的學生:

Java代碼 技術分享圖片
@Test
public void test7_2_foreach() {
ArrayList<String> classIdList = new ArrayList<String>();
classIdList.add("20000001");
classIdList.add("20000002");
List<StudentEntity> list = this.dynamicSqlMapper.getStudentListByClassIds_foreach_list(classIdList);
for (StudentEntity e : list) {
System.out.println(e.toString());
}
}

mybatis如何傳入一個list參數