mybatis中的作用

2021-03-10  本文已影响0人  lclandld

今儿在修改一个时间区间检索的问题的时候,看到了<![CDATA[]]>,以前也看到过,但是不知道是什么意思,今儿就度娘了下,进行一个自我的记录

解决的具体问题

在使用mybatis 时我们sql是写在xml 映射文件中,如果写的sql中有一些特殊的字符的话,在解析xml文件的时候会被转义,但我们不希望他被转义,所以我们要使用<![CDATA[ ]]>来解决。

<![CDATA[ ]]> 是什么

CDATA的形式如下: <![CDATA[文本内容]]> 。
CDATA的文本内容中不能出现字符串“]]>”。另外,CDATA不能嵌套。
CDATA区域是由“<![CDATA["为开始标记,以“]]>”为结束标记,注意CDATA为大写。

我要修改的代码如下

    <select id="getDetailsByPage" resultMap="StudyLineVOMap">
        select
        csl.id,
        csl.NAME,
        csl.cover,
        csl.remark,
        csl.published,
        csl.deleted,
        csl.publish_time,
        csl.create_time,
        csl.days,
        csl.tenant_id ,
        count( DISTINCT ( ctt.id ) ) AS stepNum,
        count( DISTINCT(csstc.id) ) AS courseNum,
        count( DISTINCT ( crtsl.id ) ) AS resourcesNum,
        count( DISTINCT ( cptsl.id ) ) AS paperNum
        from ccr_study_line csl
        LEFT JOIN ccr_study_step ctt ON ctt.study_line_id = csl.id
        left join ccr_study_step_to_course csstc on csstc.study_step_id = ctt.id
        LEFT JOIN ccr_resource_to_study_line crtsl on crtsl.study_line_id = csl.id
        left join ccr_paper_to_study_line cptsl on cptsl.study_line_id = csl.id
        where csl.deleted = 0 and csl.tenant_id = #{condition.tenantId}
        <if test="condition.lineName != null">
            and csl.name like concat ('%',#{condition.lineName},'%')
        </if>
        <if test="condition.startTime != null">
            and DATE_FORMAT(csl.publish_time,'%Y-%m-%d') <![CDATA[>=]]> #{condition.startTime}
        </if>
        <if test="condition.endTime != null">
            and DATE_FORMAT(csl.publish_time,'%Y-%m-%d')  <![CDATA[<=]]> #{condition.endTime}
        </if>
        <if test="condition.published != null">
            and csl.published = #{condition.published}
        </if>
        GROUP BY csl.id
        order by csl.published , csl.publish_time desc, csl.create_time desc
    </select>

上一篇 下一篇

猜你喜欢

热点阅读