动态SQL之sql标签(片段)
- sql片段,可以记录一段公共sql片段,在使用的地方通过include标签进行引入
emp_id,emp_name,age,gender,dept_id
select <include refid="empColumns">include> from t_emp
MyBatis的映射文件DynamicSQLMapper.xml
"1.0" encoding="UTF-8" ?>
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.atguigu.mybatis.mapper.DynamicSQLMapper">
emp_id,emp_name,age,gender,dept_id
<select id="getEmpByCondition" resultType="Emp">
select <include refid="empColumns">include> from t_emp
<trim prefix="where" suffixOverrides="and">
<if test="empName != null and empName != ''">
<if test="age != null and age != ''">
<if test="gender != null and gender != ''">