xml中符号转化

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>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值