xml文件中是不识别<,>,会将xml本身的元素命名搞混,得出无法解析。
1.第一种方法是转义字符,即将它们变为xml可以是别的形态:
< | < | 小于号 | > | > | 大于号 | & | & | 和 | ' | ' | 单引号 | " | " | 双引号 |
2.还有一种方法是将判断条件放到一个声明中,即<![CDATA[ ]]>
例如:
<if test="startTime != null "> ? ? AND <![CDATA[ discovery_time >= #{startTime,jdbcType=DATE} ?]]> </if> <if test="endTime != null "> ? ? AND <![CDATA[ discovery_time <= #{endTime,jdbcType=DATE} ?]]> </if>
<?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.sinosoft.springbootplus.emergencyrescue.domain.mapper.YpFiregroundInformationMapper">
<select id="selectAllFireGroundXml" resultType="com.sinosoft.springbootplus.emergencyrescue.domain.entity.YpFiregroundInformation">
select * from yp_fireground_information
<where>
<if test="ypFiregroundInformationDto.startTime!=null ">
AND <![CDATA[ discovery_time >= #{ypFiregroundInformationDto.startTime,jdbcType=DATE} ]]>
</if>
<if test="ypFiregroundInformationDto.endTime!=null">
AND <![CDATA[ discovery_time <= #{ypFiregroundInformationDto.endTime,jdbcType=DATE} ]]>
</if>
<if test="ypFiregroundInformationDto.fireSiteNo!=null">
AND fire_site_no=ypFiregroundInformationDto.fireSiteNo
</if>
</where>
limit #{ypFiregroundInformationDto.start},#{ypFiregroundInformationDto.pageSize}
</select>
</mapper>
|