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}
    ]]>
    
  • 相关阅读:
    sqlite数据库的基本操作
    java-正则表达式判断移动联通电信手机号
    基金新手常识
    Android 心跳包心跳连接 如何实现android和服务器长连接呢?推送消息的原理
    java 设计模式之模板方法
    Android 自定义view实现水波纹效果
    Android中pendingIntent的深入理解
    CentOS 7.X下 -- 配置nginx正向代理支持https
    自动化运维工具saltstack04 -- 之jinja模板
    自动化运维工具saltstack03 -- 之SaltStack的数据系统
  • 原文地址:https://www.cnblogs.com/tonyY/p/12295640.html
Copyright © 2011-2022 走看看