针对@Select({“<script></script>“})中大于小于号转义问题

使用场景:

//虽然有>=和<= 的转义,但是我在实际使用过程中,会出现“org.xml.sax.SAXParseException: 引用了实体 "ge", 但未声明它。”的错误,后来使用&gt;=和&lt;=解决问题。
@Select({“<script>
+"<if test=\"startDt != null and startDt !='' and startDt.length() > 0 \">" +
 "  AND to_char(a.crt_time, 'YYYY-MM-DD') &gt;= #{startDt} \n" +
 "</if>" +
 "<if test=\"endDt != null and endDt !='' and endDt.length() > 0 \">" +
 "  AND to_char(a.crt_time, 'YYYY-MM-DD') &lt;= #{endDt} \n" +
 "</if>" +
</script>“})

//如果不想转义,也可以用这种方式

and <![CDATA[to_char(a.crt_time, 'YYYY-MM-DD') >= #{startDt}]]>

在这种场景下,直接使用>或<出现“Caused by: org.xml.sax.SAXParseException: 元素内容必须由格式正确的字符数据或标记组成。”的错误,需要将>或< 进行转义。

显示结果实体名称

实体编号

描述

<&lt;&#60;小于号
>&gt;&#62;大于号
&le;&#8804;小于等于号
&ge;&#8805;大于等于号
&&amp;&#38;和号
"&quot;&#34;引号
'&apos;&#39;单引号(英文、IE不支持)
&ldquo;&#147;左双引号
&rdquo;&#148;右双引号
&lsquo;&#145;左单引号
&rsquo;&#146;右单引号
|&#124;竖线Vertical bar

在@Select注解中采用script标签包围拼接SQL语句时不能在标签里有>大于或<小于符号出现,但是=好像是可以出现的。

//据说in要传list或者数组,还没验证
@Select({
            "<script>",
            "select",
            "ip, content, note",
            "from t_log",
            "where note in",
            "<foreach collection='notes' item='note' open='(' separator=',' close=')'>",
            "#{note}",
            "</foreach>",
            "</script>"
    })
    List<TLog> getDataByNotes(@Param("notes") List<String> notes);


@Select({
            "<script>",
            "select",
            "ip, content, note",
            "from t_log",
            "where note in",
            "<foreach collection='notes' item='note' open='(' separator=',' close=')'>",
            "#{note}",
            "</foreach>",
            "</script>"
    })
    List<TLog> getDataByNotes2(@Param("notes") String[] notes);
   

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值