zoukankan      html  css  js  c++  java
  • mybatis sql语句配置大于号小于号的处理(元素内容必须由格式正确的字符数据或标记组成)

    原因 : Mapper.xml 文件里  < (小于)号 ,   >(大于)号 ,成对出现会被认为是括号,需要额外注意

    错误示例:

    select * from XXX
            where "DELETE" = 1
            <if test="id != null">
                and ID = #{id}
            </if>
            <if test="userIds != null and userIds.size()!=0">
                and USER_ID in
                <foreach item="item" index="index" collection="userIds"
                         open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="startTime!=null">
                and CREATE_TIME >=#{startTime}
    
            </if>
            <if test="endTime!=null">
                and CREATE_TIME <= #{endTime} 
            </if>

    解决:

    1,将 < 号换成  &lt;     > 号 换成&gt; 

    2,使用<![CDATA[  ]]> 将sql包裹

    正确示例:

    select * from XXX
            where "DELETE" = 1
            <if test="id != null">
                and ID = #{id}
            </if>
            <if test="userIds != null and userIds.size()!=0">
                and USER_ID in
                <foreach item="item" index="index" collection="userIds"
                         open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="startTime!=null">
                and CREATE_TIME >=#{startTime}
    
            </if>
            <if test="endTime!=null">
                <![CDATA[ and CREATE_TIME <= #{endTime} ]]>
            </if>
  • 相关阅读:
    利用requests, beautifulsoup包爬取股票信息网站
    Mac自带编码转换工具iconv
    Flask 快速入门
    HTML模版组件
    JavaScript正则表达式及jQuery回顾
    jQuery 教程
    Document
    Document
    Document
    Document
  • 原文地址:https://www.cnblogs.com/zhulei2/p/14246174.html
Copyright © 2011-2022 走看看