• ibatis中 CDATA 错误使用


    ibatis报错

    ## Error querying database.  Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax;
    check the manual that corresponds to your MySQL server version for the right syntax to use near '<include refid="Base_Column_List" />
          from xxxx
          where  xx' at line 2
    ### The error may exist in file [/opt/tomcat/webapps/ROOT/WEB-INF/classes/mapper/xxxx.xml]
    ### The error may involve defaultParameterMap
    ### The error occurred while setting parameters
    ### SQL: select       <include refid="Base_Column_List" />       from  
    ### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corr
    esponds to your MySQL server version for the right syntax to use near '<include refid="Base_Column_List" />
    

    如上,以上xml中的sql 语句报错。 看了下是使用了<![CDATA[ ]]>,这是XML语法。在CDATA内部的所有内容都会被解析器忽略。

    CDATA

    术语 CDATA 指的是不应由 XML 解析器进行解析的文本数据(Unparsed Character Data)。

    在 XML 元素中,"<" 和 "&" 是非法的。

    "<" 会产生错误,因为解析器会把该字符解释为新元素的开始。

    "&" 也会产生错误,因为解析器会把该字符解释为字符实体的开始。

    某些文本,比如 JavaScript 代码,包含大量 "<" 或 "&" 字符。为了避免错误,可以将脚本代码定义为 CDATA。

    CDATA 部分中的所有内容都会被解析器忽略。

    CDATA 部分由 "" 结束:,

    因为<![CDATA[把SQL语句 <include refid="Base_Column_List" />包含在里面了,所以原样子打印出来,并不会解析refid中的SQL语句。

    原始:

    <![CDATA[
    select
    <include refid="Base_Column_List" />
    from xxx
    where  status =0 and  remark = #{remark,jdbcType=VARCHAR}
    and create_time >= #{startDateStr} and create_time<= #{endDateStr}
    ]]>
    

    修改后

    select
    <include refid="Base_Column_List" />
    from xxxx
    where  status =0 and  remark = #{remark,jdbcType=VARCHAR}
    <![CDATA[
      and create_time >= #{startDateStr} and create_time<= #{endDateStr}
    ]]>
    
  • 相关阅读:
    css控制textarea固定大小不可拖动
    js绑定回车事件
    这一周的收获与总结_BP
    20140824
    【转】Hadooop学习笔记
    【转】CUDA优化小记录
    【转】CUDA程序优化要点
    cublas 矩阵相乘API详解
    CUDA 矩阵相乘完整代码
    CUDA 矩阵相乘
  • 原文地址:https://www.cnblogs.com/tonyY/p/12295640.html
Copyright © 2020-2023  润新知