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());
}
最新文章
- JUnit 简介
- QQ拼音输入法 该到放弃的时候了
- shiro 简单的身份验证 案例
- iOS完整学习步骤
- jqurey click和blur执行时间冲突
- iOS开发数据库SQLite的使用
- 【转】错误日志ID8021来源BROWSER导致电脑死机
- windows下建立文件的换行符^M导致linux下的shell脚本执行错误的解决方式
- 由两代WIN8 Surface平板看微软心态
- WebView加载页面的两种方式——网络页面和本地页面
- CentOS6.5安装MySQL5.6
- 《代码整洁之道》(Clean Code)- 读书笔记
- java http 请求的工具类
- 关于xampp中无法启动mysql,Attempting to start MySQL service...的解决办法!!
- 转载 信号量 <;第六篇>;
- jvm内存模型中-栈,方法区,程序计数器是线程安全的
- Fiddler 简介
- Video to SDI Tx Bridge模块video_data(SD-SDI)处理过程
- android EditText设置弹出数字输入法键盘
- Python基础语法——(引号、字符串、长字符串、原始字符串、Unicode)