mybatis generator:example的使用
mybatis generator生成对象和xml的时候,会生成一个example对象,看一下example在查询、修改当中的使用
1.简单查询
DemoExample example = new DemoExample(); example.createCriteria().andIdEqualTo(1L); List<Demo> demos = demoMapper.selectByExample(example); System.out.println(demos);
2.like查询
DemoExample example = new DemoExample(); //注意条件 example.createCriteria().andUserNameLike("%" + "l" + "%"); List<Demo> demos = demoMapper.selectByExample(example); System.out.println(demos);
3.排序
DemoExample example = new DemoExample(); example.setOrderByClause("id DESC"); List<Demo> demos = demoMapper.selectByExample(example); System.out.println(demos);
4.分页
DemoExample example = new DemoExample(); RowBounds rowBounds = new RowBounds(0, 10); List<Demo> demos = demoMapper.selectByExampleWithRowbounds(example,rowBounds); System.out.println(demos);
5.复杂查询((name包含l;年龄:【0~40】)or(createAt不在【0~10】))
DemoExample example = new DemoExample(); //name包含l;年龄:【0~40】 DemoExample.Criteria criteria = example.createCriteria(); criteria.andUserNameLike("%" + "l" + "%").andAgeBetween(0L,40L); //createAt不在【0~10】 DemoExample.Criteria criteria2 = example.createCriteria(); criteria2.andCreateAtNotBetween(0L,10L); example.or(criteria2); List<Demo> demos = demoMapper.selectByExample(example); System.out.println(demos);
6.附:自主生成的方法
package com.sankuai.mall.wip.dao.domain.generator; import java.util.ArrayList; import java.util.List; public class DemoExample { protected String orderByClause; protected boolean distinct; protected List<Criteria> oredCriteria; public DemoExample() { oredCriteria = new ArrayList<Criteria>(); } public void setOrderByClause(String orderByClause) { this.orderByClause = orderByClause; } public String getOrderByClause() { return orderByClause; } public void setDistinct(boolean distinct) { this.distinct = distinct; } public boolean isDistinct() { return distinct; } public List<Criteria> getOredCriteria() { return oredCriteria; } public void or(Criteria criteria) { oredCriteria.add(criteria); } public Criteria or() { Criteria criteria = createCriteriaInternal(); oredCriteria.add(criteria); return criteria; } public Criteria createCriteria() { Criteria criteria = createCriteriaInternal(); if (oredCriteria.size() == 0) { oredCriteria.add(criteria); } return criteria; } protected Criteria createCriteriaInternal() { Criteria criteria = new Criteria(); return criteria; } public void clear() { oredCriteria.clear(); orderByClause = null; distinct = false; } protected abstract static class GeneratedCriteria { protected List<Criterion> criteria; protected GeneratedCriteria() { super(); criteria = new ArrayList<Criterion>(); } public boolean isValid() { return criteria.size() > 0; } public List<Criterion> getAllCriteria() { return criteria; } public List<Criterion> getCriteria() { return criteria; } protected void addCriterion(String condition) { if (condition == null) { throw new RuntimeException("Value for condition cannot be null"); } criteria.add(new Criterion(condition)); } protected void addCriterion(String condition, Object value, String property) { if (value == null) { throw new RuntimeException("Value for " + property + " cannot be null"); } criteria.add(new Criterion(condition, value)); } protected void addCriterion(String condition, Object value1, Object value2, String property) { if (value1 == null || value2 == null) { throw new RuntimeException("Between values for " + property + " cannot be null"); } criteria.add(new Criterion(condition, value1, value2)); } public Criteria andIdIsNull() { addCriterion("id is null"); return (Criteria) this; } public Criteria andIdIsNotNull() { addCriterion("id is not null"); return (Criteria) this; } public Criteria andIdEqualTo(Long value) { addCriterion("id =", value, "id"); return (Criteria) this; } public Criteria andIdNotEqualTo(Long value) { addCriterion("id <>", value, "id"); return (Criteria) this; } public Criteria andIdGreaterThan(Long value) { addCriterion("id >", value, "id"); return (Criteria) this; } public Criteria andIdGreaterThanOrEqualTo(Long value) { addCriterion("id >=", value, "id"); return (Criteria) this; } public Criteria andIdLessThan(Long value) { addCriterion("id <", value, "id"); return (Criteria) this; } public Criteria andIdLessThanOrEqualTo(Long value) { addCriterion("id <=", value, "id"); return (Criteria) this; } public Criteria andIdIn(List<Long> values) { addCriterion("id in", values, "id"); return (Criteria) this; } public Criteria andIdNotIn(List<Long> values) { addCriterion("id not in", values, "id"); return (Criteria) this; } public Criteria andIdBetween(Long value1, Long value2) { addCriterion("id between", value1, value2, "id"); return (Criteria) this; } public Criteria andIdNotBetween(Long value1, Long value2) { addCriterion("id not between", value1, value2, "id"); return (Criteria) this; } public Criteria andUserNameIsNull() { addCriterion("user_name is null"); return (Criteria) this; } public Criteria andUserNameIsNotNull() { addCriterion("user_name is not null"); return (Criteria) this; } public Criteria andUserNameEqualTo(String value) { addCriterion("user_name =", value, "userName"); return (Criteria) this; } public Criteria andUserNameNotEqualTo(String value) { addCriterion("user_name <>", value, "userName"); return (Criteria) this; } public Criteria andUserNameGreaterThan(String value) { addCriterion("user_name >", value, "userName"); return (Criteria) this; } public Criteria andUserNameGreaterThanOrEqualTo(String value) { addCriterion("user_name >=", value, "userName"); return (Criteria) this; } public Criteria andUserNameLessThan(String value) { addCriterion("user_name <", value, "userName"); return (Criteria) this; } public Criteria andUserNameLessThanOrEqualTo(String value) { addCriterion("user_name <=", value, "userName"); return (Criteria) this; } public Criteria andUserNameLike(String value) { addCriterion("user_name like", value, "userName"); return (Criteria) this; } public Criteria andUserNameNotLike(String value) { addCriterion("user_name not like", value, "userName"); return (Criteria) this; } public Criteria andUserNameIn(List<String> values) { addCriterion("user_name in", values, "userName"); return (Criteria) this; } public Criteria andUserNameNotIn(List<String> values) { addCriterion("user_name not in", values, "userName"); return (Criteria) this; } public Criteria andUserNameBetween(String value1, String value2) { addCriterion("user_name between", value1, value2, "userName"); return (Criteria) this; } public Criteria andUserNameNotBetween(String value1, String value2) { addCriterion("user_name not between", value1, value2, "userName"); return (Criteria) this; } public Criteria andAgeIsNull() { addCriterion("age is null"); return (Criteria) this; } public Criteria andAgeIsNotNull() { addCriterion("age is not null"); return (Criteria) this; } public Criteria andAgeEqualTo(Long value) { addCriterion("age =", value, "age"); return (Criteria) this; } public Criteria andAgeNotEqualTo(Long value) { addCriterion("age <>", value, "age"); return (Criteria) this; } public Criteria andAgeGreaterThan(Long value) { addCriterion("age >", value, "age"); return (Criteria) this; } public Criteria andAgeGreaterThanOrEqualTo(Long value) { addCriterion("age >=", value, "age"); return (Criteria) this; } public Criteria andAgeLessThan(Long value) { addCriterion("age <", value, "age"); return (Criteria) this; } public Criteria andAgeLessThanOrEqualTo(Long value) { addCriterion("age <=", value, "age"); return (Criteria) this; } public Criteria andAgeIn(List<Long> values) { addCriterion("age in", values, "age"); return (Criteria) this; } public Criteria andAgeNotIn(List<Long> values) { addCriterion("age not in", values, "age"); return (Criteria) this; } public Criteria andAgeBetween(Long value1, Long value2) { addCriterion("age between", value1, value2, "age"); return (Criteria) this; } public Criteria andAgeNotBetween(Long value1, Long value2) { addCriterion("age not between", value1, value2, "age"); return (Criteria) this; } public Criteria andCreateByIsNull() { addCriterion("create_by is null"); return (Criteria) this; } public Criteria andCreateByIsNotNull() { addCriterion("create_by is not null"); return (Criteria) this; } public Criteria andCreateByEqualTo(String value) { addCriterion("create_by =", value, "createBy"); return (Criteria) this; } public Criteria andCreateByNotEqualTo(String value) { addCriterion("create_by <>", value, "createBy"); return (Criteria) this; } public Criteria andCreateByGreaterThan(String value) { addCriterion("create_by >", value, "createBy"); return (Criteria) this; } public Criteria andCreateByGreaterThanOrEqualTo(String value) { addCriterion("create_by >=", value, "createBy"); return (Criteria) this; } public Criteria andCreateByLessThan(String value) { addCriterion("create_by <", value, "createBy"); return (Criteria) this; } public Criteria andCreateByLessThanOrEqualTo(String value) { addCriterion("create_by <=", value, "createBy"); return (Criteria) this; } public Criteria andCreateByLike(String value) { addCriterion("create_by like", value, "createBy"); return (Criteria) this; } public Criteria andCreateByNotLike(String value) { addCriterion("create_by not like", value, "createBy"); return (Criteria) this; } public Criteria andCreateByIn(List<String> values) { addCriterion("create_by in", values, "createBy"); return (Criteria) this; } public Criteria andCreateByNotIn(List<String> values) { addCriterion("create_by not in", values, "createBy"); return (Criteria) this; } public Criteria andCreateByBetween(String value1, String value2) { addCriterion("create_by between", value1, value2, "createBy"); return (Criteria) this; } public Criteria andCreateByNotBetween(String value1, String value2) { addCriterion("create_by not between", value1, value2, "createBy"); return (Criteria) this; } public Criteria andCreateAtIsNull() { addCriterion("create_at is null"); return (Criteria) this; } public Criteria andCreateAtIsNotNull() { addCriterion("create_at is not null"); return (Criteria) this; } public Criteria andCreateAtEqualTo(Long value) { addCriterion("create_at =", value, "createAt"); return (Criteria) this; } public Criteria andCreateAtNotEqualTo(Long value) { addCriterion("create_at <>", value, "createAt"); return (Criteria) this; } public Criteria andCreateAtGreaterThan(Long value) { addCriterion("create_at >", value, "createAt"); return (Criteria) this; } public Criteria andCreateAtGreaterThanOrEqualTo(Long value) { addCriterion("create_at >=", value, "createAt"); return (Criteria) this; } public Criteria andCreateAtLessThan(Long value) { addCriterion("create_at <", value, "createAt"); return (Criteria) this; } public Criteria andCreateAtLessThanOrEqualTo(Long value) { addCriterion("create_at <=", value, "createAt"); return (Criteria) this; } public Criteria andCreateAtIn(List<Long> values) { addCriterion("create_at in", values, "createAt"); return (Criteria) this; } public Criteria andCreateAtNotIn(List<Long> values) { addCriterion("create_at not in", values, "createAt"); return (Criteria) this; } public Criteria andCreateAtBetween(Long value1, Long value2) { addCriterion("create_at between", value1, value2, "createAt"); return (Criteria) this; } public Criteria andCreateAtNotBetween(Long value1, Long value2) { addCriterion("create_at not between", value1, value2, "createAt"); return (Criteria) this; } public Criteria andChangeByIsNull() { addCriterion("change_by is null"); return (Criteria) this; } public Criteria andChangeByIsNotNull() { addCriterion("change_by is not null"); return (Criteria) this; } public Criteria andChangeByEqualTo(String value) { addCriterion("change_by =", value, "changeBy"); return (Criteria) this; } public Criteria andChangeByNotEqualTo(String value) { addCriterion("change_by <>", value, "changeBy"); return (Criteria) this; } public Criteria andChangeByGreaterThan(String value) { addCriterion("change_by >", value, "changeBy"); return (Criteria) this; } public Criteria andChangeByGreaterThanOrEqualTo(String value) { addCriterion("change_by >=", value, "changeBy"); return (Criteria) this; } public Criteria andChangeByLessThan(String value) { addCriterion("change_by <", value, "changeBy"); return (Criteria) this; } public Criteria andChangeByLessThanOrEqualTo(String value) { addCriterion("change_by <=", value, "changeBy"); return (Criteria) this; } public Criteria andChangeByLike(String value) { addCriterion("change_by like", value, "changeBy"); return (Criteria) this; } public Criteria andChangeByNotLike(String value) { addCriterion("change_by not like", value, "changeBy"); return (Criteria) this; } public Criteria andChangeByIn(List<String> values) { addCriterion("change_by in", values, "changeBy"); return (Criteria) this; } public Criteria andChangeByNotIn(List<String> values) { addCriterion("change_by not in", values, "changeBy"); return (Criteria) this; } public Criteria andChangeByBetween(String value1, String value2) { addCriterion("change_by between", value1, value2, "changeBy"); return (Criteria) this; } public Criteria andChangeByNotBetween(String value1, String value2) { addCriterion("change_by not between", value1, value2, "changeBy"); return (Criteria) this; } public Criteria andChangeAtIsNull() { addCriterion("change_at is null"); return (Criteria) this; } public Criteria andChangeAtIsNotNull() { addCriterion("change_at is not null"); return (Criteria) this; } public Criteria andChangeAtEqualTo(Long value) { addCriterion("change_at =", value, "changeAt"); return (Criteria) this; } public Criteria andChangeAtNotEqualTo(Long value) { addCriterion("change_at <>", value, "changeAt"); return (Criteria) this; } public Criteria andChangeAtGreaterThan(Long value) { addCriterion("change_at >", value, "changeAt"); return (Criteria) this; } public Criteria andChangeAtGreaterThanOrEqualTo(Long value) { addCriterion("change_at >=", value, "changeAt"); return (Criteria) this; } public Criteria andChangeAtLessThan(Long value) { addCriterion("change_at <", value, "changeAt"); return (Criteria) this; } public Criteria andChangeAtLessThanOrEqualTo(Long value) { addCriterion("change_at <=", value, "changeAt"); return (Criteria) this; } public Criteria andChangeAtIn(List<Long> values) { addCriterion("change_at in", values, "changeAt"); return (Criteria) this; } public Criteria andChangeAtNotIn(List<Long> values) { addCriterion("change_at not in", values, "changeAt"); return (Criteria) this; } public Criteria andChangeAtBetween(Long value1, Long value2) { addCriterion("change_at between", value1, value2, "changeAt"); return (Criteria) this; } public Criteria andChangeAtNotBetween(Long value1, Long value2) { addCriterion("change_at not between", value1, value2, "changeAt"); return (Criteria) this; } public Criteria andValidIsNull() { addCriterion("valid is null"); return (Criteria) this; } public Criteria andValidIsNotNull() { addCriterion("valid is not null"); return (Criteria) this; } public Criteria andValidEqualTo(Byte value) { addCriterion("valid =", value, "valid"); return (Criteria) this; } public Criteria andValidNotEqualTo(Byte value) { addCriterion("valid <>", value, "valid"); return (Criteria) this; } public Criteria andValidGreaterThan(Byte value) { addCriterion("valid >", value, "valid"); return (Criteria) this; } public Criteria andValidGreaterThanOrEqualTo(Byte value) { addCriterion("valid >=", value, "valid"); return (Criteria) this; } public Criteria andValidLessThan(Byte value) { addCriterion("valid <", value, "valid"); return (Criteria) this; } public Criteria andValidLessThanOrEqualTo(Byte value) { addCriterion("valid <=", value, "valid"); return (Criteria) this; } public Criteria andValidIn(List<Byte> values) { addCriterion("valid in", values, "valid"); return (Criteria) this; } public Criteria andValidNotIn(List<Byte> values) { addCriterion("valid not in", values, "valid"); return (Criteria) this; } public Criteria andValidBetween(Byte value1, Byte value2) { addCriterion("valid between", value1, value2, "valid"); return (Criteria) this; } public Criteria andValidNotBetween(Byte value1, Byte value2) { addCriterion("valid not between", value1, value2, "valid"); return (Criteria) this; } } public static class Criteria extends GeneratedCriteria { protected Criteria() { super(); } } public static class Criterion { private String condition; private Object value; private Object secondValue; private boolean noValue; private boolean singleValue; private boolean betweenValue; private boolean listValue; private String typeHandler; public String getCondition() { return condition; } public Object getValue() { return value; } public Object getSecondValue() { return secondValue; } public boolean isNoValue() { return noValue; } public boolean isSingleValue() { return singleValue; } public boolean isBetweenValue() { return betweenValue; } public boolean isListValue() { return listValue; } public String getTypeHandler() { return typeHandler; } protected Criterion(String condition) { super(); this.condition = condition; this.typeHandler = null; this.noValue = true; } protected Criterion(String condition, Object value, String typeHandler) { super(); this.condition = condition; this.value = value; this.typeHandler = typeHandler; if (value instanceof List<?>) { this.listValue = true; } else { this.singleValue = true; } } protected Criterion(String condition, Object value) { this(condition, value, null); } protected Criterion(String condition, Object value, Object secondValue, String typeHandler) { super(); this.condition = condition; this.value = value; this.secondValue = secondValue; this.typeHandler = typeHandler; this.betweenValue = true; } protected Criterion(String condition, Object value, Object secondValue) { this(condition, value, secondValue, null); } } }
package com.sankuai.mall.wip.dao.mapper.generator; import com.sankuai.mall.wip.dao.domain.generator.Demo; import com.sankuai.mall.wip.dao.domain.generator.DemoExample; import java.util.List; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.session.RowBounds; import org.springframework.stereotype.Repository; @Repository public interface DemoMapper { long countByExample(DemoExample example); int deleteByExample(DemoExample example); int insert(Demo record); int insertSelective(Demo record); List<Demo> selectByExampleWithRowbounds(DemoExample example, RowBounds rowBounds); List<Demo> selectByExample(DemoExample example); int updateByExampleSelective(@Param("record") Demo record, @Param("example") DemoExample example); int updateByExample(@Param("record") Demo record, @Param("example") DemoExample example); }
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.sankuai.mall.wip.dao.mapper.generator.DemoMapper"> <resultMap id="BaseResultMap" type="com.sankuai.mall.wip.dao.domain.generator.Demo"> <result column="id" jdbcType="BIGINT" property="id" /> <result column="user_name" jdbcType="VARCHAR" property="userName" /> <result column="age" jdbcType="BIGINT" property="age" /> <result column="create_by" jdbcType="VARCHAR" property="createBy" /> <result column="create_at" jdbcType="BIGINT" property="createAt" /> <result column="change_by" jdbcType="VARCHAR" property="changeBy" /> <result column="change_at" jdbcType="BIGINT" property="changeAt" /> <result column="valid" jdbcType="TINYINT" property="valid" /> </resultMap> <sql id="Example_Where_Clause"> <where> <foreach collection="oredCriteria" item="criteria" separator="or"> <if test="criteria.valid"> <trim prefix="(" prefixOverrides="and" suffix=")"> <foreach collection="criteria.criteria" item="criterion"> <choose> <when test="criterion.noValue"> and ${criterion.condition} </when> <when test="criterion.singleValue"> and ${criterion.condition} #{criterion.value} </when> <when test="criterion.betweenValue"> and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} </when> <when test="criterion.listValue"> and ${criterion.condition} <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=","> #{listItem} </foreach> </when> </choose> </foreach> </trim> </if> </foreach> </where> </sql> <sql id="Update_By_Example_Where_Clause"> <where> <foreach collection="example.oredCriteria" item="criteria" separator="or"> <if test="criteria.valid"> <trim prefix="(" prefixOverrides="and" suffix=")"> <foreach collection="criteria.criteria" item="criterion"> <choose> <when test="criterion.noValue"> and ${criterion.condition} </when> <when test="criterion.singleValue"> and ${criterion.condition} #{criterion.value} </when> <when test="criterion.betweenValue"> and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} </when> <when test="criterion.listValue"> and ${criterion.condition} <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=","> #{listItem} </foreach> </when> </choose> </foreach> </trim> </if> </foreach> </where> </sql> <sql id="Base_Column_List"> id, user_name, age, create_by, create_at, change_by, change_at, valid </sql> <select id="selectByExample" parameterType="com.sankuai.mall.wip.dao.domain.generator.DemoExample" resultMap="BaseResultMap"> select <if test="distinct"> distinct </if> <include refid="Base_Column_List" /> from demo <if test="_parameter != null"> <include refid="Example_Where_Clause" /> </if> <if test="orderByClause != null"> order by ${orderByClause} </if> </select> <delete id="deleteByExample" parameterType="com.sankuai.mall.wip.dao.domain.generator.DemoExample"> delete from demo <if test="_parameter != null"> <include refid="Example_Where_Clause" /> </if> </delete> <insert id="insert" parameterType="com.sankuai.mall.wip.dao.domain.generator.Demo"> insert into demo (id, user_name, age, create_by, create_at, change_by, change_at, valid) values (#{id,jdbcType=BIGINT}, #{userName,jdbcType=VARCHAR}, #{age,jdbcType=BIGINT}, #{createBy,jdbcType=VARCHAR}, #{createAt,jdbcType=BIGINT}, #{changeBy,jdbcType=VARCHAR}, #{changeAt,jdbcType=BIGINT}, #{valid,jdbcType=TINYINT}) </insert> <insert id="insertSelective" parameterType="com.sankuai.mall.wip.dao.domain.generator.Demo"> insert into demo <trim prefix="(" suffix=")" suffixOverrides=","> <if test="id != null"> id, </if> <if test="userName != null"> user_name, </if> <if test="age != null"> age, </if> <if test="createBy != null"> create_by, </if> <if test="createAt != null"> create_at, </if> <if test="changeBy != null"> change_by, </if> <if test="changeAt != null"> change_at, </if> <if test="valid != null"> valid, </if> </trim> <trim prefix="values (" suffix=")" suffixOverrides=","> <if test="id != null"> #{id,jdbcType=BIGINT}, </if> <if test="userName != null"> #{userName,jdbcType=VARCHAR}, </if> <if test="age != null"> #{age,jdbcType=BIGINT}, </if> <if test="createBy != null"> #{createBy,jdbcType=VARCHAR}, </if> <if test="createAt != null"> #{createAt,jdbcType=BIGINT}, </if> <if test="changeBy != null"> #{changeBy,jdbcType=VARCHAR}, </if> <if test="changeAt != null"> #{changeAt,jdbcType=BIGINT}, </if> <if test="valid != null"> #{valid,jdbcType=TINYINT}, </if> </trim> </insert> <select id="countByExample" parameterType="com.sankuai.mall.wip.dao.domain.generator.DemoExample" resultType="java.lang.Long"> select count(*) from demo <if test="_parameter != null"> <include refid="Example_Where_Clause" /> </if> </select> <update id="updateByExampleSelective" parameterType="map"> update demo <set> <if test="record.id != null"> id = #{record.id,jdbcType=BIGINT}, </if> <if test="record.userName != null"> user_name = #{record.userName,jdbcType=VARCHAR}, </if> <if test="record.age != null"> age = #{record.age,jdbcType=BIGINT}, </if> <if test="record.createBy != null"> create_by = #{record.createBy,jdbcType=VARCHAR}, </if> <if test="record.createAt != null"> create_at = #{record.createAt,jdbcType=BIGINT}, </if> <if test="record.changeBy != null"> change_by = #{record.changeBy,jdbcType=VARCHAR}, </if> <if test="record.changeAt != null"> change_at = #{record.changeAt,jdbcType=BIGINT}, </if> <if test="record.valid != null"> valid = #{record.valid,jdbcType=TINYINT}, </if> </set> <if test="_parameter != null"> <include refid="Update_By_Example_Where_Clause" /> </if> </update> <update id="updateByExample" parameterType="map"> update demo set id = #{record.id,jdbcType=BIGINT}, user_name = #{record.userName,jdbcType=VARCHAR}, age = #{record.age,jdbcType=BIGINT}, create_by = #{record.createBy,jdbcType=VARCHAR}, create_at = #{record.createAt,jdbcType=BIGINT}, change_by = #{record.changeBy,jdbcType=VARCHAR}, change_at = #{record.changeAt,jdbcType=BIGINT}, valid = #{record.valid,jdbcType=TINYINT} <if test="_parameter != null"> <include refid="Update_By_Example_Where_Clause" /> </if> </update> <select id="selectByExampleWithRowbounds" parameterType="com.sankuai.mall.wip.dao.domain.generator.DemoExample" resultMap="BaseResultMap"> select <if test="distinct"> distinct </if> <include refid="Base_Column_List" /> from demo <if test="_parameter != null"> <include refid="Example_Where_Clause" /> </if> <if test="orderByClause != null"> order by ${orderByClause} </if> </select> </mapper>