zoukankan      html  css  js  c++  java
  • 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}
    ]]>
    
  • 相关阅读:
    lubuntu18.04如何创建APPImage软件的桌面快捷方式
    查找一个程序所在的路径
    lubuntu18.04如何用命令行打开一个应用(application)
    linux shell(ubuntu18.04.4 LTS) autostart to change the wallpaper
    bash常用的快捷键
    mkfs格式化分区(为分区写入文件系统)
    fdisk交互
    Linux fdisk命令创建逻辑分区
    Linux fdisk命令创建扩展分区过程
    fdisk创立主分区过程
  • 原文地址:https://www.cnblogs.com/tonyY/p/12295640.html
Copyright © 2011-2022 走看看