使用场景:
//虽然有>=和<= 的转义,但是我在实际使用过程中,会出现“org.xml.sax.SAXParseException: 引用了实体 "ge", 但未声明它。”的错误,后来使用>=和<=解决问题。
@Select({“<script>
+"<if test=\"startDt != null and startDt !='' and startDt.length() > 0 \">" +
" AND to_char(a.crt_time, 'YYYY-MM-DD') >= #{startDt} \n" +
"</if>" +
"<if test=\"endDt != null and endDt !='' and endDt.length() > 0 \">" +
" AND to_char(a.crt_time, 'YYYY-MM-DD') <= #{endDt} \n" +
"</if>" +
</script>“})
//如果不想转义,也可以用这种方式
and <![CDATA[to_char(a.crt_time, 'YYYY-MM-DD') >= #{startDt}]]>
在这种场景下,直接使用>或<出现“Caused by: org.xml.sax.SAXParseException: 元素内容必须由格式正确的字符数据或标记组成。”的错误,需要将>或< 进行转义。
显示结果 | 实体名称 | 实体编号 | 描述 |
---|---|---|---|
< | < | < | 小于号 |
> | > | > | 大于号 |
≤ | ≤ | ≤ | 小于等于号 |
≥ | ≥ | ≥ | 大于等于号 |
& | & | & | 和号 |
" | " | " | 引号 |
' | ' | ' | 单引号(英文、IE不支持) |
“ | “ | “ | 左双引号 |
” | ” | ” | 右双引号 |
‘ | ‘ | ‘ | 左单引号 |
’ | ’ | ’ | 右单引号 |
| | | | 竖线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);