xml文件中是不识别<,>,会将xml本身的元素命名搞混,得出无法解析。


1.第一种方法是转义字符,即将它们变为xml可以是别的形态:

&lt; < 小于号
&gt; > 大于号
&amp; &
&apos; ' 单引号
&quot; " 双引号


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>

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐