MyBatis框架
5.6 foreach
- foreach 主要用户循环迭代
collection: 要迭代的集合
item: 当前从集合中迭代出的元素
open: 开始字符
close:结束字符
separator: 元素与元素之间的分隔符
index:
迭代的是List集合: index表示的当前元素的下标
迭代的Map集合: index表示的当前元素的key
<select id="getEmpsByConditionForeach" resultType="com.atguigu.mybatis.beans.Employee"> select id , last_name, email ,gender from tbl_employee where id in <foreach collection="ids" item="curr_id" open="(" close=")" separator="," > #{curr_id} </foreach> </select> |
5.7 sql
- sql 标签是用于抽取可重用的sql片段,将相同的,使用频繁的SQL片段抽取出来,单独定义,方便多次引用.
- 抽取SQL:
<sql id="selectSQL"> select id , last_name, email ,gender from tbl_employee </sql> |
- 引用SQL:
<include refid="selectSQL"></include> |