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());

      }

    本人目前处于学习阶段,各位大神多多提宝贵的建议!
  • 相关阅读:
    购物菜单
    数据库
    增删改查
    页面交互
    计算器
    2020.9.21
    团队-团队编程项目中国象棋-项目总结
    团队-团队编程项目作业名称-最终程序
    课后作业-阅读任务-阅读提问-4
    《20171130-构建之法:现代软件工程-阅读笔记》
  • 原文地址:https://www.cnblogs.com/FanSunny/p/4766481.html
Copyright © 2011-2022 走看看