zoukankan      html  css  js  c++  java
  • 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());

      }

    本人目前处于学习阶段,各位大神多多提宝贵的建议!
  • 相关阅读:
    截取字符串的值
    Tomcat发布项目方法
    struts标签
    正则表达式范例
    树的操作方法
    树结点动态帮定事件
    I/O 流和对象序列化
    Word中的字体大小
    script实现的日期表示
    JavaScript弹出窗口技巧
  • 原文地址:https://www.cnblogs.com/FanSunny/p/4766481.html
Copyright © 2011-2022 走看看