1. 程式人生 > >mybatis異常:The content of elements must consist of well-formed character data or markup的解決方法

mybatis異常:The content of elements must consist of well-formed character data or markup的解決方法

今天做專案的時候,要加入選擇開始日期結束日期然後根據日期範圍刪選資料顯示出來的功能,於是我在mybatis的Mapper xml檔案中使用where語句寫了形如:

select * from t_stuff where time < #{startTime} and time > #{endTime}

的語句

然後居然報錯了,錯誤如下:

The content of elements must consist of well-formed character data or markup.

介似擁喂嘛呢?(為什麼,天津話)

這個錯誤的意思是,不是格式良好的xml

也就是我們的書寫格式有誤,原來是因為編譯器自動把sql語句中的小於號當成了開始標籤,那就當然會報錯了,我們只要改成如下這樣:

select * from t_stuff where time > #{endTime} <![CDATA[ and time < #{startTime} ]]>

就OK了 !