mybatis中的if?test判斷入?yún)⒌闹祮栴}
mybatis if test判斷入?yún)⒌闹?/h2>
1.第一種判斷方式
<if test=' requisition != null and requisition == "Y" '> ? ?AND 表字段 = #{requisition} </if>
2.第二種判斷方式
<if test=" requisition != null and requisition == 'Y'.toString() "> AND 表字段 = #{requisition} </if>
if test動(dòng)態(tài)判斷數(shù)字時(shí)出現(xiàn)的錯(cuò)誤
mybatis中if test判斷數(shù)字
在實(shí)現(xiàn)搜索功能時(shí)碰到的錯(cuò)誤,很多時(shí)候我們會(huì)在數(shù)據(jù)庫中使用一個(gè)字段來作為狀態(tài)保存,如:0=男,1=女;0=禁止,1=啟用等。
無論我選擇停用、還是啟用,都將整個(gè)表格的數(shù)據(jù)顯示出來,沒有起到篩選的作用。
通過排除,找到了導(dǎo)致問題的代碼:
<select id="queryAllByLimit" resultMap="SystemMenuMap"> select id, pid, title, icon, href, sort, status from system_menu <where> <if test="systemMenu.status != null and systemMenu.status != '' "> and status = #{systemMenu.status} </if> </where> </select>
改為:
<select id="queryAllByLimit" resultMap="SystemMenuMap"> select id, pid, title, icon, href, sort, status from system_menu <where> <if test="systemMenu.status != null"> and status = #{systemMenu.status} </if> </where> </select>
原因:
<if test="systemMenu.status != null and systemMenu.status != '' ">
只對(duì)判斷String類型的字符串時(shí)起作用,由于status是Integer類型,判斷條件不成立,沒起到作用。如:當(dāng)傳入的值是1時(shí),’1’會(huì)被解析成字符。
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
永久解決 Intellij idea 報(bào)錯(cuò):Error :java 不支持發(fā)行版本5的問題
這篇文章主要介紹了永久解決 Intellij idea 報(bào)錯(cuò):Error :java 不支持發(fā)行版本5的問題,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-02-02Java基礎(chǔ)學(xué)習(xí)之構(gòu)造方法詳解
這篇文章主要為大家詳細(xì)介紹了Java基礎(chǔ)學(xué)習(xí)中構(gòu)造方法的概述及注意事項(xiàng),文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)Java有一定幫助,需要的可以參考一下2022-08-08Jmeter?BlazeMeter實(shí)現(xiàn)web錄制過程
BlazeMeter是一款與Apache JMeter兼容的chrome插件,采用BlazeMeter可以方便的進(jìn)行流量錄制和腳本生成,作為接口測(cè)試腳本編寫的一個(gè)基礎(chǔ),這篇文章主要介紹了Jmeter?BlazeMeter實(shí)現(xiàn)web錄制,需要的朋友可以參考下2021-12-12Spring Boot Actuator監(jiān)控端點(diǎn)小結(jié)
這篇文章主要介紹了Spring Boot Actuator監(jiān)控端點(diǎn)小結(jié),需要的朋友可以參考下2017-06-06