<selectid="selectByExample"resultMap="BaseResultMap"parameterType="com.test.entity.TestQuery">
SELECT
*
FROM
test s
WHERE 1=1
<!-- 创建时间 --><iftest="createTime!=null and createTime!=''">
AND s.create_time = #{createTime,jdbcType=TIMESTAMP}
</if><!-- 开始创建时间,结束创建时间都不为空 --><iftest="beginCreateTime!=null and beginCreateTime!='' and endCreateTime!=null and endCreateTime!=''">
AND s.create_time >= #{beginCreateTime,jdbcType=TIMESTAMP}
AND s.create_time <= #{endCreateTime,jdbcType=TIMESTAMP}
</if><!-- 开始不为空,结束为空 null --><iftest="beginCreateTime!=null and beginCreateTime!='' and endCreateTime==null">
AND s.create_time >= #{beginCreateTime,jdbcType=TIMESTAMP}
</if><!-- 开始不为空,结束为空 '' --><iftest="beginCreateTime!=null and beginCreateTime!='' and endCreateTime==''">
AND s.create_time >= #{beginCreateTime,jdbcType=TIMESTAMP}
</if><!-- 开始为空 null,结束不为空 --><iftest="beginCreateTime==null and endCreateTime!=null and endCreateTime!=''">
AND s.create_time <= #{endCreateTime,jdbcType=TIMESTAMP}
</if><!-- 开始为空 '',结束不为空 --><iftest="beginCreateTime=='' and endCreateTime!=null and endCreateTime!=''">
AND s.create_time <= #{endCreateTime,jdbcType=TIMESTAMP}
</if></select>
对 null 和 ” 分开进行判断&lt;select id="selectByExample" resultMap="BaseResultMap" parameterType="com.test.entity.TestQuery"&gt;SELECT * FROM test s WHERE 1=1 &lt;!-- 创建时间 --&gt; ...