sqlMap.xml配置文件中迭代一个集合的方式

比如:根据班级号查询学生的信息,参数是list

1、foreach的用法:【写法一】

<select id="getStudentListByClassId" resultMap="StudentResultList">

  select * form Student stu where stu.ClassId in

  <foreach collection="list" item="classList" open="(" separator="," close=")">

    #{classList}      [item是一个别名而已]

  </foreach>

</select>

2、criteria的用法:【写法二】

 

 <isNotEmpty property="criteria">
   <iterate property="criteria" conjunction="and" prepend="and"
 open="(" close=")">
    $criteria[].paramName$ $criteria[].arithmeticType$ #criteria[].paramValue#
 </iterate>

JAVA测试方法编写:(接口声明)

 public List<Student> getStudentListByClassId(List<String> classList);

测试代码,查询学生中在10000,10001这两个班级的学生:(具体实现方法)

  List<String> classList = new ArrayList<String>();

  classList.add("10000");

  classList.add("10001");

  List<Student> studentList = studentMapper.getStudentListByClassId(classList);

  for(Student stu:studentList){

    System.out.println(studentList.toString());

  }

 

posted @ 2015-08-28 14:34  FanSunny  阅读(528)  评论(0编辑  收藏  举报