<mappernamespace="com.atguigu.mybatis.dao.EmployeeMapper"><!--
namespace:名称空间;指定为接口的全类名
id:唯一标识
resultType:返回值类型
#{id}:从传递过来的参数中取出id值
public Employee getEmpById(Integer id);
--><!--public Map<Integer, Employee> getEmpByLastNameLikeReturnMap(String lastName); --><selectid="getEmpByLastNameLikeReturnMap"resultType="com.atguigu.mybatis.bean.Employee">
select * from tbl_employee where last_name like #{lastName}
</select><!--public Map<String, Object> getEmpByIdReturnMap(Integer id); --><selectid="getEmpByIdReturnMap"resultType="map">
select * from tbl_employee where id=#{id}
</select><!-- public List<Employee> getEmpsByLastNameLike(String lastName); --><!--resultType:如果返回的是一个集合,要写集合中元素的类型 --><selectid="getEmpsByLastNameLike"resultType="com.atguigu.mybatis.bean.Employee">
select * from tbl_employee where last_name like #{lastName}
</select><!-- public Employee getEmpByMap(Map<String, Object> map); --><selectid="getEmpByMap"resultType="com.atguigu.mybatis.bean.Employee">
select * from ${tableName} where id=${id} and last_name=#{lastName}
</select><!-- public Employee getEmpByIdAndLastName(Integer id,String lastName);--><selectid="getEmpByIdAndLastName"resultType="com.atguigu.mybatis.bean.Employee">
select * from tbl_employee where id = #{id} and last_name=#{lastName}
</select><selectid="getEmpById"resultType="com.atguigu.mybatis.bean.Employee">
select * from tbl_employee where id = #{id}
</select><selectid="getEmpById"resultType="com.atguigu.mybatis.bean.Employee"databaseId="mysql">
select * from tbl_employee where id = #{id}
</select><selectid="getEmpById"resultType="com.atguigu.mybatis.bean.Employee"databaseId="oracle">
select EMPLOYEE_ID id,LAST_NAME lastName,EMAIL email
from employees where EMPLOYEE_ID=#{id}
</select><!-- public void addEmp(Employee employee); --><!-- parameterType:参数类型,可以省略,
获取自增主键的值:
mysql支持自增主键,自增主键值的获取,mybatis也是利用statement.getGenreatedKeys();
useGeneratedKeys="true";使用自增主键获取主键值策略
keyProperty;指定对应的主键属性,也就是mybatis获取到主键值以后,将这个值封装给javaBean的哪个属性
--><insertid="addEmp"parameterType="com.atguigu.mybatis.bean.Employee"useGeneratedKeys="true"keyProperty="id"databaseId="mysql">
insert into tbl_employee(last_name,email,gender)
values(#{lastName},#{email},#{gender})
</insert><!--
获取非自增主键的值:
Oracle不支持自增;Oracle使用序列来模拟自增;
每次插入的数据的主键是从序列中拿到的值;如何获取到这个值;
--><insertid="addEmp"databaseId="oracle"><!--
keyProperty:查出的主键值封装给javaBean的哪个属性
order="BEFORE":当前sql在插入sql之前运行
AFTER:当前sql在插入sql之后运行
resultType:查出的数据的返回值类型
BEFORE运行顺序:
先运行selectKey查询id的sql;查出id值封装给javaBean的id属性
在运行插入的sql;就可以取出id属性对应的值
AFTER运行顺序:
先运行插入的sql(从序列中取出新值作为id);
再运行selectKey查询id的sql;
--><selectKeykeyProperty="id"order="BEFORE"resultType="Integer"><!-- 编写查询主键的sql语句 --><!-- BEFORE-->
select EMPLOYEES_SEQ.nextval from dual
<!-- AFTER:
select EMPLOYEES_SEQ.currval from dual --></selectKey><!-- 插入时的主键是从序列中拿到的 --><!-- BEFORE:-->
insert into employees(EMPLOYEE_ID,LAST_NAME,EMAIL)
values(#{id},#{lastName},#{email<!-- ,jdbcType=NULL -->})
<!-- AFTER:
insert into employees(EMPLOYEE_ID,LAST_NAME,EMAIL)
values(employees_seq.nextval,#{lastName},#{email}) --></insert><!-- public void updateEmp(Employee employee); --><updateid="updateEmp">
update tbl_employee
set last_name=#{lastName},email=#{email},gender=#{gender}
where id=#{id}
</update><!-- public void deleteEmpById(Integer id); --><deleteid="deleteEmpById">
delete from tbl_employee where id=#{id}
</delete></mapper>
resultMap
<mappernamespace="com.atguigu.mybatis.dao.DepartmentMapper"><!--public Department getDeptById(Integer id); --><selectid="getDeptById"resultType="com.atguigu.mybatis.bean.Department">
select id,dept_name departmentName from tbl_dept where id=#{id}
</select><!--
public class Department {
private Integer id;
private String departmentName;
private List<Employee> emps;
did dept_name || eid last_name email gender
--><!--嵌套结果集的方式,使用collection标签定义关联的集合类型的属性封装规则 --><resultMaptype="com.atguigu.mybatis.bean.Department"id="MyDept"><idcolumn="did"property="id"/><resultcolumn="dept_name"property="departmentName"/><!--
collection定义关联集合类型的属性的封装规则
ofType:指定集合里面元素的类型
--><collectionproperty="emps"ofType="com.atguigu.mybatis.bean.Employee"><!-- 定义这个集合中元素的封装规则 --><idcolumn="eid"property="id"/><resultcolumn="last_name"property="lastName"/><resultcolumn="email"property="email"/><resultcolumn="gender"property="gender"/></collection></resultMap><!-- public Department getDeptByIdPlus(Integer id); --><selectid="getDeptByIdPlus"resultMap="MyDept">
SELECT d.id did,d.dept_name dept_name,
e.id eid,e.last_name last_name,e.email email,e.gender gender
FROM tbl_dept d
LEFT JOIN tbl_employee e
ON d.id=e.d_id
WHERE d.id=#{id}
</select><!-- collection:分段查询 --><resultMaptype="com.atguigu.mybatis.bean.Department"id="MyDeptStep"><idcolumn="id"property="id"/><idcolumn="dept_name"property="departmentName"/><collectionproperty="emps"select="com.atguigu.mybatis.dao.EmployeeMapperPlus.getEmpsByDeptId"column="{deptId=id}"fetchType="lazy"></collection></resultMap><!-- public Department getDeptByIdStep(Integer id); --><selectid="getDeptByIdStep"resultMap="MyDeptStep">
select id,dept_name from tbl_dept where id=#{id}
</select><!-- 扩展:多列的值传递过去:
将多列的值封装map传递;
column="{key1=column1,key2=column2}"
fetchType="lazy":表示使用延迟加载;
- lazy:延迟
- eager:立即
--></mapper>
封装规则
单个参数:mybatis不会做特殊处理,
#{参数名/任意名}:取出参数值。
多个参数:mybatis会做特殊处理。
多个参数会被封装成 一个map,
key:param1...paramN,或者参数的索引也可以
value:传入的参数值
#{}就是从map中获取指定的key的值;
异常:
org.apache.ibatis.binding.BindingException:
Parameter 'id' not found.
Available parameters are [1, 0, param1, param2]
操作:
方法:public Employee getEmpByIdAndLastName(Integer id,String lastName);
取值:#{id},#{lastName}
【命名参数】:明确指定封装参数时map的key;@Param("id")
多个参数会被封装成 一个map,
key:使用@Param注解指定的值
value:参数值
#{指定的key}取出对应的参数值
POJO:
如果多个参数正好是我们业务逻辑的数据模型,我们就可以直接传入pojo;
#{属性名}:取出传入的pojo的属性值
Map:
如果多个参数不是业务模型中的数据,没有对应的pojo,不经常使用,为了方便,我们也可以传入map
#{key}:取出map中对应的值
TO:
如果多个参数不是业务模型中的数据,但是经常要使用,推荐来编写一个TO(Transfer Object)数据传输对象
Page{
int index;
int size;
}
========================思考================================
public Employee getEmp(@Param("id")Integer id,String lastName);
取值:id==>#{id/param1} lastName==>#{param2}
public Employee getEmp(Integer id,@Param("e")Employee emp);
取值:id==>#{param1} lastName===>#{param2.lastName/e.lastName}
##特别注意:如果是Collection(List、Set)类型或者是数组,
也会特殊处理。也是把传入的list或者数组封装在map中。
key:Collection(collection),如果是List还可以使用这个key(list)
数组(array)
public Employee getEmpById(List<Integer> ids);
取值:取出第一个id的值: #{list[0]}
========================结合源码,mybatis怎么处理参数==========================
总结:参数多时会封装map,为了不混乱,我们可以使用@Param来指定封装时使用的key;
#{key}就可以取出map中的值;
(@Param("id")Integer id,@Param("lastName")String lastName);
ParamNameResolver解析参数封装map的;
//1、names:{0=id, 1=lastName};构造器的时候就确定好了
确定流程:
1.获取每个标了param注解的参数的@Param的值:id,lastName; 赋值给name;
2.每次解析一个参数给map中保存信息:(key:参数索引,value:name的值)
name的值:
标注了param注解:注解的值
没有标注:
1.全局配置:useActualParamName(jdk1.8):name=参数名
2.name=map.size();相当于当前元素的索引
{0=id, 1=lastName,2=2}
args【1,"Tom",'hello'】:
public Object getNamedParams(Object[] args) {
final int paramCount = names.size();
//1、参数为null直接返回
if (args == null || paramCount == 0) {
return null;
//2、如果只有一个元素,并且没有Param注解;args[0]:单个参数直接返回
} else if (!hasParamAnnotation && paramCount == 1) {
return args[names.firstKey()];
//3、多个元素或者有Param标注
} else {
final Map<String, Object> param = new ParamMap<Object>();
int i = 0;
//4、遍历names集合;{0=id, 1=lastName,2=2}
for (Map.Entry<Integer, String> entry : names.entrySet()) {
//names集合的value作为key; names集合的key又作为取值的参考args[0]:args【1,"Tom"】:
//eg:{id=args[0]:1,lastName=args[1]:Tom,2=args[2]}
param.put(entry.getValue(), args[entry.getKey()]);
// add generic param names (param1, param2, ...)param
//额外的将每一个参数也保存到map中,使用新的key:param1...paramN
//效果:有Param注解可以#{指定的key},或者#{param1}
final String genericParamName = GENERIC_NAME_PREFIX + String.valueOf(i + 1);
// ensure not to overwrite parameter named with @Param
if (!names.containsValue(genericParamName)) {
param.put(genericParamName, args[entry.getKey()]);
}
i++;
}
return param;
}
}
}
===========================参数值的获取======================================
#{}:可以获取map中的值或者pojo对象属性的值;
${}:可以获取map中的值或者pojo对象属性的值;
select * from tbl_employee where id=${id} and last_name=#{lastName}
Preparing: select * from tbl_employee where id=2 and last_name=?
区别:
#{}:是以预编译的形式,将参数设置到sql语句中;PreparedStatement;防止sql注入
${}:取出的值直接拼装在sql语句中;会有安全问题;
大多情况下,我们去参数的值都应该去使用#{};
原生jdbc不支持占位符的地方我们就可以使用${}进行取值
比如分表、排序。。。;按照年份分表拆分
select * from ${year}_salary where xxx;
select * from tbl_employee order by ${f_name} ${order}
#{}:更丰富的用法:
规定参数的一些规则:
javaType、 jdbcType、 mode(存储过程)、 numericScale、
resultMap、 typeHandler、 jdbcTypeName、 expression(未来准备支持的功能);
jdbcType通常需要在某种特定的条件下被设置:
在我们数据为null的时候,有些数据库可能不能识别mybatis对null的默认处理。比如Oracle(报错);
JdbcType OTHER:无效的类型;因为mybatis对所有的null都映射的是原生Jdbc的OTHER类型,oracle不能正确处理;
由于全局配置中:jdbcTypeForNull=OTHER;oracle不支持;两种办法
1、#{email,jdbcType=OTHER};
2、jdbcTypeForNull=NULL
<setting name="jdbcTypeForNull" value="NULL"/>
案例解析
<mappernamespace="com.atguigu.mybatis.dao.EmployeeMapperPlus"><!--自定义某个javaBean的封装规则
type:自定义规则的Java类型
id:唯一id方便引用
--><resultMaptype="com.atguigu.mybatis.bean.Employee"id="MySimpleEmp"><!--指定主键列的封装规则
id定义主键会底层有优化;
column:指定哪一列
property:指定对应的javaBean属性
--><idcolumn="id"property="id"/><!-- 定义普通列封装规则 --><resultcolumn="last_name"property="lastName"/><!-- 其他不指定的列会自动封装:我们只要写resultMap就把全部的映射规则都写上。 --><resultcolumn="email"property="email"/><resultcolumn="gender"property="gender"/></resultMap><!-- resultMap:自定义结果集映射规则; --><!-- public Employee getEmpById(Integer id); --><selectid="getEmpById"resultMap="MySimpleEmp">
select * from tbl_employee where id=#{id}
</select><!--
场景一:
查询Employee的同时查询员工对应的部门
Employee===Department
一个员工有与之对应的部门信息;
id last_name gender d_id did dept_name (private Department dept;)
--><!--
联合查询:级联属性封装结果集
--><resultMaptype="com.atguigu.mybatis.bean.Employee"id="MyDifEmp"><idcolumn="id"property="id"/><resultcolumn="last_name"property="lastName"/><resultcolumn="gender"property="gender"/><resultcolumn="did"property="dept.id"/><resultcolumn="dept_name"property="dept.departmentName"/></resultMap><!--
使用association定义关联的单个对象的封装规则;
--><resultMaptype="com.atguigu.mybatis.bean.Employee"id="MyDifEmp2"><idcolumn="id"property="id"/><resultcolumn="last_name"property="lastName"/><resultcolumn="gender"property="gender"/><!-- association可以指定联合的javaBean对象
property="dept":指定哪个属性是联合的对象
javaType:指定这个属性对象的类型[不能省略]
--><associationproperty="dept"javaType="com.atguigu.mybatis.bean.Department"><idcolumn="did"property="id"/><resultcolumn="dept_name"property="departmentName"/></association></resultMap><!-- public Employee getEmpAndDept(Integer id);--><selectid="getEmpAndDept"resultMap="MyDifEmp">
SELECT e.id id,e.last_name last_name,e.gender gender,e.d_id d_id,
d.id did,d.dept_name dept_name FROM tbl_employee e,tbl_dept d
WHERE e.d_id=d.id AND e.id=#{id}
</select><!-- 使用association进行分步查询:
1、先按照员工id查询员工信息
2、根据查询员工信息中的d_id值去部门表查出部门信息
3、部门设置到员工中;
--><!-- id last_name email gender d_id --><resultMaptype="com.atguigu.mybatis.bean.Employee"id="MyEmpByStep"><idcolumn="id"property="id"/><resultcolumn="last_name"property="lastName"/><resultcolumn="email"property="email"/><resultcolumn="gender"property="gender"/><!-- association定义关联对象的封装规则
select:表明当前属性是调用select指定的方法查出的结果
column:指定将哪一列的值传给这个方法
流程:使用select指定的方法(传入column指定的这列参数的值)查出对象,并封装给property指定的属性
--><associationproperty="dept"select="com.atguigu.mybatis.dao.DepartmentMapper.getDeptById"column="d_id"></association></resultMap><!-- public Employee getEmpByIdStep(Integer id);--><selectid="getEmpByIdStep"resultMap="MyEmpByStep">
select * from tbl_employee where id=#{id}
<iftest="_parameter!=null">
and 1=1
</if></select><!-- 可以使用延迟加载(懒加载);(按需加载)
Employee==>Dept:
我们每次查询Employee对象的时候,都将一起查询出来。
部门信息在我们使用的时候再去查询;
分段查询的基础之上加上两个配置:
--><!-- ==================association============================ --><!--
场景二:
查询部门的时候将部门对应的所有员工信息也查询出来:注释在DepartmentMapper.xml中
--><!-- public List<Employee> getEmpsByDeptId(Integer deptId); --><selectid="getEmpsByDeptId"resultType="com.atguigu.mybatis.bean.Employee">
select * from tbl_employee where d_id=#{deptId}
</select><!-- =======================鉴别器============================ --><!-- <discriminator javaType=""></discriminator>
鉴别器:mybatis可以使用discriminator判断某列的值,然后根据某列的值改变封装行为
封装Employee:
如果查出的是女生:就把部门信息查询出来,否则不查询;
如果是男生,把last_name这一列的值赋值给email;
--><resultMaptype="com.atguigu.mybatis.bean.Employee"id="MyEmpDis"><idcolumn="id"property="id"/><resultcolumn="last_name"property="lastName"/><resultcolumn="email"property="email"/><resultcolumn="gender"property="gender"/><!--
column:指定判定的列名
javaType:列值对应的java类型 --><discriminatorjavaType="string"column="gender"><!--女生 resultType:指定封装的结果类型;不能缺少。/resultMap--><casevalue="0"resultType="com.atguigu.mybatis.bean.Employee"><associationproperty="dept"select="com.atguigu.mybatis.dao.DepartmentMapper.getDeptById"column="d_id"></association></case><!--男生 ;如果是男生,把last_name这一列的值赋值给email; --><casevalue="1"resultType="com.atguigu.mybatis.bean.Employee"><idcolumn="id"property="id"/><resultcolumn="last_name"property="lastName"/><resultcolumn="last_name"property="email"/><resultcolumn="gender"property="gender"/></case></discriminator></resultMap></mapper>
动态SQL语句
<mappernamespace="com.atguigu.mybatis.dao.EmployeeMapperDynamicSQL"><!--
• if:判断
• choose (when, otherwise):分支选择;带了break的swtich-case
如果带了id就用id查,如果带了lastName就用lastName查;只会进入其中一个
• trim 字符串截取(where(封装查询条件), set(封装修改条件))
• foreach 遍历集合
--><!-- 查询员工,要求,携带了哪个字段查询条件就带上这个字段的值 --><!-- public List<Employee> getEmpsByConditionIf(Employee employee); --><selectid="getEmpsByConditionIf"resultType="com.atguigu.mybatis.bean.Employee">
select * from tbl_employee
<!-- where --><where><!-- test:判断表达式(OGNL)
OGNL参照PPT或者官方文档。
c:if test
从参数中取值进行判断
遇见特殊符号应该去写转义字符:
&&:
--><iftest="id!=null">
id=#{id}
</if><iftest="lastName!=null && lastName!=""">
and last_name like #{lastName}
</if><iftest="email!=null and email.trim()!=""">
and email=#{email}
</if><!-- ognl会进行字符串与数字的转换判断 "0"==0 --><iftest="gender==0 or gender==1">
and gender=#{gender}
</if></where></select><!--public List<Employee> getEmpsByConditionTrim(Employee employee); --><selectid="getEmpsByConditionTrim"resultType="com.atguigu.mybatis.bean.Employee">
select * from tbl_employee
<!-- 后面多出的and或者or where标签不能解决
prefix="":前缀:trim标签体中是整个字符串拼串 后的结果。
prefix给拼串后的整个字符串加一个前缀
prefixOverrides="":
前缀覆盖: 去掉整个字符串前面多余的字符
suffix="":后缀
suffix给拼串后的整个字符串加一个后缀
suffixOverrides=""
后缀覆盖:去掉整个字符串后面多余的字符
--><!-- 自定义字符串的截取规则 --><trimprefix="where"suffixOverrides="and"><iftest="id!=null">
id=#{id} and
</if><iftest="lastName!=null && lastName!=""">
last_name like #{lastName} and
</if><iftest="email!=null and email.trim()!=""">
email=#{email} and
</if><!-- ognl会进行字符串与数字的转换判断 "0"==0 --><iftest="gender==0 or gender==1">
gender=#{gender}
</if></trim></select><!-- public List<Employee> getEmpsByConditionChoose(Employee employee); --><selectid="getEmpsByConditionChoose"resultType="com.atguigu.mybatis.bean.Employee">
select * from tbl_employee
<where><!-- 如果带了id就用id查,如果带了lastName就用lastName查;只会进入其中一个 --><choose><whentest="id!=null">
id=#{id}
</when><whentest="lastName!=null">
last_name like #{lastName}
</when><whentest="email!=null">
email = #{email}
</when><otherwise>
gender = 0
</otherwise></choose></where></select><!--public void updateEmp(Employee employee); --><updateid="updateEmp"><!-- Set标签的使用 -->
update tbl_employee
<set><iftest="lastName!=null">
last_name=#{lastName},
</if><iftest="email!=null">
email=#{email},
</if><iftest="gender!=null">
gender=#{gender}
</if></set>
where id=#{id}
<!--
Trim:更新拼串
update tbl_employee
<trim prefix="set" suffixOverrides=",">
<if test="lastName!=null">
last_name=#{lastName},
</if>
<if test="email!=null">
email=#{email},
</if>
<if test="gender!=null">
gender=#{gender}
</if>
</trim>
where id=#{id} --></update><!--public List<Employee> getEmpsByConditionForeach(List<Integer> ids); --><selectid="getEmpsByConditionForeach"resultType="com.atguigu.mybatis.bean.Employee">
select * from tbl_employee
<!--
collection:指定要遍历的集合:
list类型的参数会特殊处理封装在map中,map的key就叫list
item:将当前遍历出的元素赋值给指定的变量
separator:每个元素之间的分隔符
open:遍历出所有结果拼接一个开始的字符
close:遍历出所有结果拼接一个结束的字符
index:索引。遍历list的时候是index就是索引,item就是当前值
遍历map的时候index表示的就是map的key,item就是map的值
#{变量名}就能取出变量的值也就是当前遍历出的元素
--><foreachcollection="ids"item="item_id"separator=","open="where id in("close=")">
#{item_id}
</foreach></select><!-- 批量保存 --><!--public void addEmps(@Param("emps")List<Employee> emps); --><!--MySQL下批量保存:可以foreach遍历 mysql支持values(),(),()语法--><insertid="addEmps">
insert into tbl_employee(
<includerefid="insertColumn"></include>
)
values
<foreachcollection="emps"item="emp"separator=",">
(#{emp.lastName},#{emp.email},#{emp.gender},#{emp.dept.id})
</foreach></insert><!-- --><!-- 这种方式需要数据库连接属性allowMultiQueries=true;
这种分号分隔多个sql可以用于其他的批量操作(删除,修改) --><!-- <insert id="addEmps">
<foreach collection="emps" item="emp" separator=";">
insert into tbl_employee(last_name,email,gender,d_id)
values(#{emp.lastName},#{emp.email},#{emp.gender},#{emp.dept.id})
</foreach>
</insert> --><!-- Oracle数据库批量保存:
Oracle不支持values(),(),()
Oracle支持的批量方式
1、多个insert放在begin - end里面
begin
insert into employees(employee_id,last_name,email)
values(employees_seq.nextval,'test_001','test_001@atguigu.com');
insert into employees(employee_id,last_name,email)
values(employees_seq.nextval,'test_002','test_002@atguigu.com');
end;
2、利用中间表:
insert into employees(employee_id,last_name,email)
select employees_seq.nextval,lastName,email from(
select 'test_a_01' lastName,'test_a_e01' email from dual
union
select 'test_a_02' lastName,'test_a_e02' email from dual
union
select 'test_a_03' lastName,'test_a_e03' email from dual
)
--><insertid="addEmps"databaseId="oracle"><!-- oracle第一种批量方式 --><!-- <foreach collection="emps" item="emp" open="begin" close="end;">
insert into employees(employee_id,last_name,email)
values(employees_seq.nextval,#{emp.lastName},#{emp.email});
</foreach> --><!-- oracle第二种批量方式 -->
insert into employees(
<!-- 引用外部定义的sql --><includerefid="insertColumn"><propertyname="testColomn"value="abc"/></include>
)
<foreachcollection="emps"item="emp"separator="union"open="select employees_seq.nextval,lastName,email from("close=")">
select #{emp.lastName} lastName,#{emp.email} email from dual
</foreach></insert><!-- 两个内置参数:
不只是方法传递过来的参数可以被用来判断,取值。。。
mybatis默认还有两个内置参数:
_parameter:代表整个参数
单个参数:_parameter就是这个参数
多个参数:参数会被封装为一个map;_parameter就是代表这个map
_databaseId:如果配置了databaseIdProvider标签。
_databaseId就是代表当前数据库的别名oracle
--><!--public List<Employee> getEmpsTestInnerParameter(Employee employee); --><selectid="getEmpsTestInnerParameter"resultType="com.atguigu.mybatis.bean.Employee"><!-- bind:可以将OGNL表达式的值绑定到一个变量中,方便后来引用这个变量的值 --><bindname="_lastName"value="'%'+lastName+'%'"/><iftest="_databaseId=='mysql'">
select * from tbl_employee
<iftest="_parameter!=null">
where last_name like #{lastName}
</if></if><iftest="_databaseId=='oracle'">
select * from employees
<iftest="_parameter!=null">
where last_name like #{_parameter.lastName}
</if></if></select><!--
抽取可重用的sql片段。方便后面引用
1、sql抽取:经常将要查询的列名,或者插入用的列名抽取出来方便引用
2、include来引用已经抽取的sql:
3、include还可以自定义一些property,sql标签内部就能使用自定义的属性
include-property:取值的正确方式${prop},
#{不能使用这种方式}
--><sqlid="insertColumn"><iftest="_databaseId=='oracle'">
employee_id,last_name,email
</if><iftest="_databaseId=='mysql'">
last_name,email,gender,d_id
</if></sql></mapper>