mybatis中使用大于小于等于的正確方法
在mybatis中sql是寫在xml映射文件中的,如果sql中有一些特殊字符的話,在解析xml文件的時(shí)候就會(huì)被轉(zhuǎn)義,如若不希望被轉(zhuǎn)義,那該怎么辦呢?
方法一:使用特殊轉(zhuǎn)義字符例如,>=開(kāi)始日期 并且<=結(jié)束日期
> > 大于號(hào)
< < 小于號(hào)
<if test='searchTimeBegin != null and searchTimeBegin != ’’'> AND tcci.consume_time >= CONCAT(#{searchTimeBegin},’ 00:00:00’) </if> <if test='searchTimeEnd != null and searchTimeEnd != ’’'> AND tcci.consume_time <= CONCAT(#{searchTimeEnd},’ 23:59:59’) </if>
符號(hào) 小于 小于等于 大于 大于等于 和 單引號(hào) 雙引號(hào) 原符號(hào) < <= > >= & ’ ' 替換符號(hào) < <= > >= & ' "
方法二:使用<![CDATA[ ]]>符號(hào)這里面的內(nèi)容將不被解析
<if test='beginTime!=null'> AND DATE (os.show_start_time) >= DATE(#{beginTime}) </if> <if test='endTime!=null'> AND DATE (os.show_start_time) <![CDATA[<=]]> DATE(#{endTime}) </if>
在mybatis中<=不能使用,需要使用上面任意一種方法轉(zhuǎn)義,但是>=可以使用!
到此這篇關(guān)于mybatis中使用大于小于等于的正確方法的文章就介紹到這了,更多相關(guān)mybatis 大于小于等于內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. golang實(shí)現(xiàn)mysql數(shù)據(jù)庫(kù)事務(wù)的提交與回滾2. MyBatis如何實(shí)現(xiàn)流式查詢的示例代碼3. Mybatis Limit實(shí)現(xiàn)分頁(yè)功能4. mybatis plus動(dòng)態(tài)數(shù)據(jù)源切換及查詢過(guò)程淺析5. 解決db2事務(wù)日志已滿及日志磁盤空間已滿問(wèn)題辦法詳解6. SQLite教程(二):C/C++接口簡(jiǎn)介7. MyBatis SELECT基本查詢實(shí)現(xiàn)方法詳解8. 基于mysql的論壇(3)9. Mybatis在sqlite中無(wú)法讀寫byte[]類問(wèn)題的解決辦法10. Mybatis分頁(yè)P(yáng)ageHelper插件代碼實(shí)例
