<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC"-//mybatis.org//DTD Mapper 3.0//EN" "https://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mappernamespace="com.newboy.demo3.mapper.EmpMapper"> <sqlid="commonSelete"> select * from emp </sql> <deleteid="deleteByIds"> delete from emp where in <foreachcollection="ids"item="id"separator=","open="("close=")"> #{id} </foreach> </delete><selectid="list"resultType="com.newboy.demo3.pojo.Emp"> <includerefid="commonSelete"></include> <where> <iftest="name != null"> name like concat('%', #{name}, '%') </if> <iftest="gender != null"> and gender = #{gender} </if> <iftest="begin != null and end != null"> and entrydate between #{begin} and #{end} </if> </where> order by update_time desc </select> </mapper>
if标签
用于判断条件是否成立。使用test属性进行条件判断,如果条件为true,则拼接SQL
1 2 3
<iftest="name != null"> name like concat('%',#{name},'%') </if>