<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapperPUBLIC"-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > <mappernamespace="com.sky.mapper.CategoryMapper"> <selectid="pageQuery"resultType="com.sky.entity.Category"> select * from category <where> <iftest="name != null and name != ''"> and name like concat('%',#{name},'%') </if> <iftest="type != null">and type = #{type}</if> </where> order by create_time desc </select> </mapper>
特别注意:
SQL 中的 WHERE 子句不支持用逗号分隔多个条件。条件之间应该用逻辑运算符(如 AND 或 OR)连接。