When writing code today, because of business, I need to use greater than and less than symbols in mybatis, so I use it directly in SQL.
SELECT * FROM test WHERE 1 = 1 AND start_date <= CURRENT_DATE AND end_date >= CURRENT_DATE
However, when executing, the total error is reported:
Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 74; columnNumber: 17; Element content must consist of well-formed character data or markup.
Remove AND start_date >= CURRENT_DATE AND end_date <= CURRENT_DATE, there is no problem, so it is determined that the problem is caused by the greater than and less than symbols.
So I thought of special symbols, so I replaced > and < with escape characters, and then there was no problem.
SELECT * FROM test WHERE 1 = 1 AND start_date <= CURRENT_DATE AND end_date >= CURRENT_DATE
P.S. XML escape characters
< < 小于号
> > 大于号
& & 和
' ' 单引号
" " 双引号
Reprint address: https://blog.csdn.net/gisredevelopment/article/details/27870833